diff options
author | Christian W. Damus | 2017-12-23 21:18:00 +0000 |
---|---|---|
committer | Christian W. Damus | 2017-12-23 22:08:53 +0000 |
commit | b8f00d122a3f8a6bd94ea8fee8058572e074df89 (patch) | |
tree | 9a3528986572a25548816af5a4f71c23f38a2805 /tests/junit/plugins/uml | |
parent | 8ab94c0f6fbacc843b2fc6dc473f5274d12d70bc (diff) | |
download | org.eclipse.papyrus-b8f00d122a3f8a6bd94ea8fee8058572e074df89.tar.gz org.eclipse.papyrus-b8f00d122a3f8a6bd94ea8fee8058572e074df89.tar.xz org.eclipse.papyrus-b8f00d122a3f8a6bd94ea8fee8058572e074df89.zip |
Bug 528343: [I18N] Preference checking overhead for models that don't use i18n
Fix test failures on build machine that is configured for en_US locale.
Also fix new listener API for preference changes that didn't account for
changes applied directly to the preference store (some code does this).
(cherry-picked from streams/3.0-maintenance)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=528343
Change-Id: I7cbe89117bb8cd410ec871dacce78e65937b6880
(cherry picked from commit 791896186a78d125dd13fb1330c65f0067190599)
Diffstat (limited to 'tests/junit/plugins/uml')
2 files changed, 79 insertions, 14 deletions
diff --git a/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/DefaultLocaleRule.java b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/DefaultLocaleRule.java new file mode 100644 index 00000000000..7d8b16146b1 --- /dev/null +++ b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/DefaultLocaleRule.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2017 Christian W. Damus and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus - initial API and implementation + *******************************************************************************/ +package org.eclipse.papyrus.uml.internationalization.tests; + +import java.util.Locale; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * A JUnit rule that sets the VM's default locale for the duration of a test. + * + * @author Christian W. Damus + */ +public class DefaultLocaleRule implements TestRule { + + private final Locale locale; + + private Locale restore; + + public DefaultLocaleRule(Locale locale) { + super(); + + this.locale = locale; + } + + @Override + public Statement apply(Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + restore = Locale.getDefault(); + + Locale.setDefault(locale); + + try { + base.evaluate(); + } finally { + Locale.setDefault(restore); + } + } + }; + } + +} diff --git a/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationUMLItemProviderAdapterFactoryTest.java b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationUMLItemProviderAdapterFactoryTest.java index 9a82fdb2f59..987bb9ef05b 100644 --- a/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationUMLItemProviderAdapterFactoryTest.java +++ b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationUMLItemProviderAdapterFactoryTest.java @@ -19,6 +19,8 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; +import java.util.Locale; + import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.ecore.EObject; @@ -27,7 +29,9 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.papyrus.junit.utils.rules.PluginResource; import org.eclipse.papyrus.uml.internationalization.edit.providers.InternationalizationUMLItemProviderAdapterFactory; +import org.eclipse.papyrus.uml.internationalization.tests.DefaultLocaleRule; import org.junit.After; +import org.junit.ClassRule; import org.junit.Test; /** @@ -36,11 +40,17 @@ import org.junit.Test; * @author Christian W. Damus */ @SuppressWarnings("nls") -@PluginResource({"resources/model.di", "resources/model_en_US.properties", "resources/model_fr_FR.properties"}) +@PluginResource({ "resources/model.di", "resources/model_en_US.properties", "resources/model_fr_FR.properties" }) public class InternationalizationUMLItemProviderAdapterFactoryTest extends AbstractUMLInternationalizationTest { + // Set a locale in the VM that does not have a corresponding properties file, otherwise + // if the host system happens to be en_US then these tests will fail because the framework + // will default to enabling internationalization + @ClassRule + public static final DefaultLocaleRule defaultLocale = new DefaultLocaleRule(Locale.KOREAN); + private AdapterFactory factory; - + /** * Initializes e. */ @@ -51,7 +61,7 @@ public class InternationalizationUMLItemProviderAdapterFactoryTest extends Abstr @Test public void normalAdapters() { checkUMLNoLabels(); - + // The last adapter added should be our item-provider Adapter last = modelClass.eAdapters().get(modelClass.eAdapters().size() - 1); assertThat(last.getClass().getSimpleName(), is("ClassItemProvider")); @@ -61,20 +71,20 @@ public class InternationalizationUMLItemProviderAdapterFactoryTest extends Abstr public void rebuildAdapters() { int initialAdapterCount = modelClass.eAdapters().size(); checkUMLNoLabels(); - + int newAdapterCount = modelClass.eAdapters().size(); assertThat(newAdapterCount, greaterThan(initialAdapterCount)); - + Adapter adapter = modelClass.eAdapters().get(newAdapterCount - 1); - + setLanguagePreference(modelClass, "fr_FR"); setInternationalizationPreference(modelClass, true); - + // Purged the adapters assertThat(modelClass.eAdapters().size(), lessThan(newAdapterCount)); - + checkUMLFrenchLabels(); - + // Just replaced the adapter with a new one assertThat(modelClass.eAdapters().size(), is(newAdapterCount)); Adapter newAdapter = modelClass.eAdapters().get(newAdapterCount - 1); @@ -84,21 +94,21 @@ public class InternationalizationUMLItemProviderAdapterFactoryTest extends Abstr // // Test framework // - + @Override protected ILabelProvider initLabelProvider() { factory = new InternationalizationUMLItemProviderAdapterFactory(); - + // Initially disable the i18n setInternationalizationPreference(fixture.getModelResource(), false); - + return new AdapterFactoryLabelProvider(factory); } - + @After public void disposeFactory() { labelProvider.dispose(); - ((IDisposable)factory).dispose(); + ((IDisposable) factory).dispose(); } /** |