diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java index f0727426def..c8f45ab6473 100644 --- a/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java +++ b/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java @@ -19,11 +19,13 @@ import org.openstreetmap.josm.data.osm.Tag; import org.openstreetmap.josm.data.validation.Severity; import org.openstreetmap.josm.data.validation.TestError; +import org.openstreetmap.josm.testutils.annotations.I18n; import org.openstreetmap.josm.testutils.annotations.TaggingPresets; /** * JUnit Test of {@link TagChecker}. */ +@I18n @TaggingPresets class TagCheckerTest { List test(OsmPrimitive primitive) throws IOException { diff --git a/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java index 4f085766ad3..0852b7a0618 100644 --- a/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java +++ b/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java @@ -23,6 +23,7 @@ import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; +import org.openstreetmap.josm.testutils.annotations.I18n; import org.openstreetmap.josm.testutils.annotations.Main; import org.openstreetmap.josm.testutils.annotations.Projection; @@ -32,6 +33,7 @@ @BasicPreferences @Main @Projection +@I18n class MarkerLayerTest { /** * Setup tests diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java index 910c568eb2a..fc0125dabb6 100644 --- a/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java +++ b/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java @@ -19,11 +19,13 @@ import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector.PresetClassification; import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector.PresetClassifications; +import org.openstreetmap.josm.testutils.annotations.Territories; import org.xml.sax.SAXException; /** * Unit tests of {@link PresetClassifications} class. */ +@Territories class PresetClassificationsTest { static final PresetClassifications classifications = new PresetClassifications(); diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java index fa414d81c82..391e282bb5d 100644 --- a/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java +++ b/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java @@ -17,6 +17,7 @@ import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.gui.tagging.presets.items.Check; import org.openstreetmap.josm.gui.tagging.presets.items.Key; +import org.openstreetmap.josm.testutils.annotations.Territories; import org.xml.sax.SAXException; /** @@ -76,6 +77,7 @@ void testExternalEntityResolving() throws IOException { * @throws SAXException if any XML error occurs * @throws IOException if any I/O error occurs */ + @Territories @Test void testReadDefaultPresets() throws SAXException, IOException { String presetfile = "resource://data/defaultpresets.xml"; diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java b/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java index 4baedecb66e..ae515470e51 100644 --- a/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java +++ b/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java @@ -45,15 +45,22 @@ public void beforeEach(ExtensionContext context) { String language = AnnotationUtils.findFirstParentAnnotation(context, I18n.class).map(I18n::value).orElse("en"); if (!Locale.getDefault().equals(LanguageInfo.getLocale(language, false))) { org.openstreetmap.josm.tools.I18n.set(language); + // We want to have a consistent "country", so we don't use a locale with a country code from the original locale. + // Unless someone specified it via the _ syntax. + if (!language.contains("_")) { + Locale.setDefault(LanguageInfo.getLocale(language, false)); + } } } @Override public void afterEach(ExtensionContext context) { - if (!Locale.ENGLISH.equals(Locale.getDefault())) { + Locale original = org.openstreetmap.josm.tools.I18n.getOriginalLocale(); + if (original == null) { org.openstreetmap.josm.tools.I18n.set("en"); - org.openstreetmap.josm.tools.I18n.set(org.openstreetmap.josm.tools.I18n.getOriginalLocale().getLanguage()); - Locale.setDefault(Locale.ENGLISH); + } else if (!original.equals(Locale.getDefault())) { + org.openstreetmap.josm.tools.I18n.set(original.getLanguage()); + Locale.setDefault(original); } } } diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java b/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java index 9901693971a..42d970a0547 100644 --- a/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java +++ b/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java @@ -7,6 +7,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.Collection; +import java.util.Locale; +import java.util.Objects; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; @@ -31,6 +33,7 @@ class TaggingPresetsExtension implements BeforeEachCallback, BeforeAllCallback { private static int expectedHashcode = 0; + private static Locale lastLocale; @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { @@ -47,9 +50,10 @@ public void beforeEach(ExtensionContext extensionContext) { */ public static synchronized void setup() { final Collection oldPresets = org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.getTaggingPresets(); - if (oldPresets.isEmpty() || expectedHashcode != oldPresets.hashCode()) { + if (oldPresets.isEmpty() || expectedHashcode != oldPresets.hashCode() || !Objects.equals(lastLocale, Locale.getDefault())) { org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.readFromPreferences(); expectedHashcode = org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.getTaggingPresets().hashCode(); + lastLocale = Locale.getDefault(); } } }