Subject: [PATCH] Fix #23418: Improve unit test consistency when run with non-English locales
---
Index: test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java
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/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java	(revision 18957)
+++ b/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java	(date 1706190288961)
@@ -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<TestError> test(OsmPrimitive primitive) throws IOException {
Index: test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java
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/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java	(revision 18957)
+++ b/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java	(date 1705409737622)
@@ -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
Index: test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java
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/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java	(revision 18957)
+++ b/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java	(date 1706189694846)
@@ -50,10 +50,12 @@
 
         @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);
             }
         }
     }
Index: test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java
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/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java	(revision 18957)
+++ b/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java	(date 1706191851459)
@@ -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 static synchronized void setup() {
             final Collection<TaggingPreset> 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();
             }
         }
     }
