Ticket #23418: 23418.2.patch

File 23418.2.patch, 5.4 KB (added by taylor.smock, 15 months ago)

Modify @TaggingPresets to reread presets when locale changes

  • test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java

    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  
    1919import org.openstreetmap.josm.data.osm.Tag;
    2020import org.openstreetmap.josm.data.validation.Severity;
    2121import org.openstreetmap.josm.data.validation.TestError;
     22import org.openstreetmap.josm.testutils.annotations.I18n;
    2223import org.openstreetmap.josm.testutils.annotations.TaggingPresets;
    2324
    2425/**
    2526 * JUnit Test of {@link TagChecker}.
    2627 */
     28@I18n
    2729@TaggingPresets
    2830class TagCheckerTest {
    2931    List<TestError> test(OsmPrimitive primitive) throws IOException {
  • 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 b  
    2323import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2424import org.openstreetmap.josm.spi.preferences.Config;
    2525import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     26import org.openstreetmap.josm.testutils.annotations.I18n;
    2627import org.openstreetmap.josm.testutils.annotations.Main;
    2728import org.openstreetmap.josm.testutils.annotations.Projection;
    2829
     
    3233@BasicPreferences
    3334@Main
    3435@Projection
     36@I18n
    3537class MarkerLayerTest {
    3638    /**
    3739     * Setup tests
  • 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 b  
    5050
    5151        @Override
    5252        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) {
    5455                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);
    5759            }
    5860        }
    5961    }
  • 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 b  
    77import java.lang.annotation.RetentionPolicy;
    88import java.lang.annotation.Target;
    99import java.util.Collection;
     10import java.util.Locale;
     11import java.util.Objects;
    1012
    1113import org.junit.jupiter.api.extension.BeforeAllCallback;
    1214import org.junit.jupiter.api.extension.BeforeEachCallback;
     
    3133
    3234    class TaggingPresetsExtension implements BeforeEachCallback, BeforeAllCallback {
    3335        private static int expectedHashcode = 0;
     36        private static Locale lastLocale;
    3437
    3538        @Override
    3639        public void beforeAll(ExtensionContext extensionContext) throws Exception {
     
    4750         */
    4851        public static synchronized void setup() {
    4952            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())) {
    5154                org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.readFromPreferences();
    5255                expectedHashcode = org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.getTaggingPresets().hashCode();
     56                lastLocale = Locale.getDefault();
    5357            }
    5458        }
    5559    }