Changeset 18718 in josm for trunk


Ignore:
Timestamp:
2023-04-26T23:13:00+02:00 (12 months ago)
Author:
taylor.smock
Message:

See #22898: JOSM Validator CLI errors out when is run with --load-preferences argument

There was an additional problem related to the directories setup order.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java

    r18714 r18718  
    163163    public void processArguments(final String[] argArray) {
    164164        try {
     165            // for right-left-hand traffic cache file, needed for preferences
     166            Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
    165167            // Ensure that preferences are only in memory
    166168            Config.setPreferencesInstance(new MemoryPreferences());
     
    348350        Logging.setLogLevel(this.logLevel);
    349351        HttpClient.setFactory(Http1Client::new);
    350         Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
    351352        Config.setUrlsProvider(JosmUrls.getInstance());
    352353        ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));
  • trunk/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java

    r18714 r18718  
    55import static org.junit.jupiter.api.Assertions.assertEquals;
    66import static org.junit.jupiter.api.Assertions.assertTrue;
    7 import static org.junit.jupiter.api.Assertions.fail;
    87
    98import java.io.ByteArrayInputStream;
     
    1211import java.io.OutputStream;
    1312import java.io.PrintWriter;
    14 import java.lang.reflect.InvocationTargetException;
     13import java.io.UncheckedIOException;
    1514import java.nio.charset.StandardCharsets;
    1615import java.nio.file.Files;
     
    2928import javax.json.JsonObject;
    3029import javax.json.JsonReader;
    31 import javax.swing.SwingUtilities;
    32 
     30
     31import mockit.Mock;
     32import mockit.MockUp;
    3333import org.junit.jupiter.api.AfterEach;
    3434import org.junit.jupiter.api.BeforeEach;
    3535import org.junit.jupiter.api.Test;
     36import org.junit.jupiter.api.extension.RegisterExtension;
    3637import org.junit.jupiter.api.io.TempDir;
    3738import org.junit.jupiter.params.ParameterizedTest;
     
    4344import org.openstreetmap.josm.data.osm.DataSet;
    4445import org.openstreetmap.josm.data.osm.Node;
    45 import org.openstreetmap.josm.gui.MainApplication;
    4646import org.openstreetmap.josm.io.OsmWriter;
    4747import org.openstreetmap.josm.io.OsmWriterFactory;
    4848import org.openstreetmap.josm.spi.lifecycle.Lifecycle;
    4949import org.openstreetmap.josm.spi.preferences.Config;
     50import org.openstreetmap.josm.testutils.annotations.AnnotationUtils;
    5051import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     52import org.openstreetmap.josm.testutils.annotations.ThreadSync;
    5153import org.openstreetmap.josm.tools.Logging;
    5254import org.openstreetmap.josm.tools.Utils;
    53 
    54 import mockit.Mock;
    55 import mockit.MockUp;
    5655
    5756/**
     
    6160@BasicPreferences
    6261class ValidatorCLITest {
     62    @RegisterExtension
     63    ThreadSync.ThreadSyncExtension threadSync = new ThreadSync.ThreadSyncExtension();
     64
    6365    @TempDir
    6466    static File temporaryDirectory;
    6567
    6668    TestHandler handler;
    67 
    68     private static void synchronizeThreads() {
    69         MainApplication.worker.execute(() -> { /* Sync worker thread */ });
    70         try {
    71             SwingUtilities.invokeAndWait(() -> { /* Sync EDT thread */ });
    72         } catch (InterruptedException e) {
    73             Thread.currentThread().interrupt();
    74             fail(e);
    75         } catch (InvocationTargetException e) {
    76             fail(e);
    77         }
    78     }
    7969
    8070    @BeforeEach
     
    8777
    8878    @AfterEach
    89     void tearDown() throws InterruptedException, InvocationTargetException {
    90         synchronizeThreads();
     79    void tearDown() {
    9180        Logging.getLogger().removeHandler(this.handler);
    9281        this.handler.close();
     
    113102                        return Files.copy(file.toPath(), Paths.get(temporaryDirectory.getPath(), renamedValidator)).getFileName().toString();
    114103                    } catch (IOException e) {
    115                         fail(e);
     104                        throw new UncheckedIOException(e);
    116105                    }
    117                     return null;
    118106                }).map(Arguments::of);
    119107    }
     
    138126        final File outputFile = new File(outputPath);
    139127        assertTrue(outputFile.exists());
    140         synchronizeThreads();
     128        threadSync.threadSync();
    141129        final List<JsonObject> errors = readJsonObjects(outputFile.toPath());
    142130        assertEquals(3, errors.stream().map(ValidatorCLITest::getMessage).filter("Overlapping Identical Landuses"::equals).count());
     
    182170     */
    183171    @Test
    184     void testNonRegression22898(final @TempDir Path preferencesLocation) throws IOException {
     172    void testNonRegression22898(final @TempDir Path preferencesLocation) throws IOException, ReflectiveOperationException {
     173        AnnotationUtils.resetStaticClass(Config.class);
    185174        final ValidatorCLI validatorCLI = new ValidatorCLI();
    186175        final Path preferences = preferencesLocation.resolve("preferences.xml");
Note: See TracChangeset for help on using the changeset viewer.