Subject: [PATCH] Fix #23418: Improve unit test consistency when run with non-English locales
---
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java
|
a
|
b
|
|
| 19 | 19 | import org.openstreetmap.josm.data.osm.Tag; |
| 20 | 20 | import org.openstreetmap.josm.data.validation.Severity; |
| 21 | 21 | import org.openstreetmap.josm.data.validation.TestError; |
| | 22 | import org.openstreetmap.josm.testutils.annotations.I18n; |
| 22 | 23 | import org.openstreetmap.josm.testutils.annotations.TaggingPresets; |
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * JUnit Test of {@link TagChecker}. |
| 26 | 27 | */ |
| | 28 | @I18n |
| 27 | 29 | @TaggingPresets |
| 28 | 30 | class TagCheckerTest { |
| 29 | 31 | List<TestError> test(OsmPrimitive primitive) throws IOException { |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java
|
a
|
b
|
|
| 23 | 23 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
| 24 | 24 | import org.openstreetmap.josm.spi.preferences.Config; |
| 25 | 25 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences; |
| | 26 | import org.openstreetmap.josm.testutils.annotations.I18n; |
| 26 | 27 | import org.openstreetmap.josm.testutils.annotations.Main; |
| 27 | 28 | import org.openstreetmap.josm.testutils.annotations.Projection; |
| 28 | 29 | |
| … |
… |
|
| 32 | 33 | @BasicPreferences |
| 33 | 34 | @Main |
| 34 | 35 | @Projection |
| | 36 | @I18n |
| 35 | 37 | class MarkerLayerTest { |
| 36 | 38 | /** |
| 37 | 39 | * Setup tests |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java b/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java
|
a
|
b
|
|
| 50 | 50 | |
| 51 | 51 | @Override |
| 52 | 52 | public void afterEach(ExtensionContext context) { |
| 53 | | if (!Locale.ENGLISH.equals(Locale.getDefault())) { |
| | 53 | Locale original = org.openstreetmap.josm.tools.I18n.getOriginalLocale(); |
| | 54 | if (original == null) { |
| 54 | 55 | org.openstreetmap.josm.tools.I18n.set("en"); |
| 55 | | org.openstreetmap.josm.tools.I18n.set(org.openstreetmap.josm.tools.I18n.getOriginalLocale().getLanguage()); |
| 56 | | Locale.setDefault(Locale.ENGLISH); |
| | 56 | } else if (!original.equals(Locale.getDefault())) { |
| | 57 | org.openstreetmap.josm.tools.I18n.set(original.getLanguage()); |
| | 58 | Locale.setDefault(original); |
| 57 | 59 | } |
| 58 | 60 | } |
| 59 | 61 | } |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java b/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java
|
a
|
b
|
|
| 7 | 7 | import java.lang.annotation.RetentionPolicy; |
| 8 | 8 | import java.lang.annotation.Target; |
| 9 | 9 | import java.util.Collection; |
| | 10 | import java.util.Locale; |
| | 11 | import java.util.Objects; |
| 10 | 12 | |
| 11 | 13 | import org.junit.jupiter.api.extension.BeforeAllCallback; |
| 12 | 14 | import org.junit.jupiter.api.extension.BeforeEachCallback; |
| … |
… |
|
| 31 | 33 | |
| 32 | 34 | class TaggingPresetsExtension implements BeforeEachCallback, BeforeAllCallback { |
| 33 | 35 | private static int expectedHashcode = 0; |
| | 36 | private static Locale lastLocale; |
| 34 | 37 | |
| 35 | 38 | @Override |
| 36 | 39 | public void beforeAll(ExtensionContext extensionContext) throws Exception { |
| … |
… |
|
| 47 | 50 | */ |
| 48 | 51 | public static synchronized void setup() { |
| 49 | 52 | final Collection<TaggingPreset> oldPresets = org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.getTaggingPresets(); |
| 50 | | if (oldPresets.isEmpty() || expectedHashcode != oldPresets.hashCode()) { |
| | 53 | if (oldPresets.isEmpty() || expectedHashcode != oldPresets.hashCode() || !Objects.equals(lastLocale, Locale.getDefault())) { |
| 51 | 54 | org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.readFromPreferences(); |
| 52 | 55 | expectedHashcode = org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.getTaggingPresets().hashCode(); |
| | 56 | lastLocale = Locale.getDefault(); |
| 53 | 57 | } |
| 54 | 58 | } |
| 55 | 59 | } |