Ticket #22898: 22898.patch

File 22898.patch, 3.7 KB (added by taylor.smock, 2 years ago)

Add non-regression test, simplify original patch

  • src/org/openstreetmap/josm/data/validation/ValidatorCLI.java

    Subject: [PATCH] #22898
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
    a b  
    430430            final IPreferences pref = Config.getPref();
    431431            if (pref instanceof MemoryPreferences) {
    432432                final MemoryPreferences memoryPreferences = (MemoryPreferences) pref;
    433                 tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
    434                         .forEach(entry -> memoryPreferences.putSetting(entry.getKey(), entry.getValue()));
     433                tempPreferences.getAllSettings().forEach(memoryPreferences::putSetting);
    435434            } else {
    436435                throw new JosmRuntimeException(tr("Preferences are not the expected type"));
    437436            }
  • test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java b/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java
    a b  
    99import java.io.ByteArrayInputStream;
    1010import java.io.File;
    1111import java.io.IOException;
     12import java.io.OutputStream;
    1213import java.io.PrintWriter;
    1314import java.lang.reflect.InvocationTargetException;
    1415import java.nio.charset.StandardCharsets;
     
    4546import org.openstreetmap.josm.io.OsmWriter;
    4647import org.openstreetmap.josm.io.OsmWriterFactory;
    4748import org.openstreetmap.josm.spi.lifecycle.Lifecycle;
     49import org.openstreetmap.josm.spi.preferences.Config;
    4850import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    4951import org.openstreetmap.josm.tools.Logging;
    5052import org.openstreetmap.josm.tools.Utils;
     
    175177        Files.deleteIfExists(Paths.get(errorPath));
    176178    }
    177179
     180    /**
     181     * A non-regression test for #22898: Validator CLI errors out when is run with --load-preferences argument
     182     */
     183    @Test
     184    void testNonRegression22898(final @TempDir Path preferencesLocation) throws IOException {
     185        final ValidatorCLI validatorCLI = new ValidatorCLI();
     186        final Path preferences = preferencesLocation.resolve("preferences.xml");
     187        try (OutputStream fos = Files.newOutputStream(preferences)) {
     188            final String pref = "<config>\n" +
     189                    "    <preferences operation=\"replace\">\n" +
     190                    "        <list key='plugins'>\n" +
     191                    "          <entry value='baz'/>\n" +
     192                    "        </list>\n" +
     193                    "    </preferences>\n" +
     194                    "</config>";
     195            fos.write(pref.getBytes(StandardCharsets.UTF_8));
     196        }
     197        validatorCLI.processArguments(new String[]{"--load-preferences=" + preferences,
     198                "--input", "resources/styles/standard/elemstyles.mapcss"});
     199        assertEquals(Collections.singletonList("baz"), Config.getPref().getList("plugins"));
     200    }
     201
    178202    /**
    179203     * Read json objects from a file
    180204     * @param path The file to read