From 86cc1a50ca68215fa824379d326a37bf42cac037 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Mon, 6 Nov 2023 07:08:29 -0700 Subject: [PATCH] Update tests to use JOSM JUnit 5 @Annotations Signed-off-by: Taylor Smock --- .../HighwayNameChangeActionTest.java | 32 ++++++++--------- .../HighwayNameListenerTest.java | 35 ++++++++----------- .../HighwayNameModificationTest.java | 11 +++--- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeActionTest.java b/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeActionTest.java index c43b4a0..19e2cef 100644 --- a/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeActionTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeActionTest.java @@ -1,12 +1,10 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.highwaynamemodification; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.swing.JOptionPane; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; @@ -15,6 +13,8 @@ import java.util.logging.Handler; import java.util.logging.LogRecord; +import javax.swing.JOptionPane; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,38 +27,34 @@ import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.spi.preferences.Config; -import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; +import org.openstreetmap.josm.testutils.annotations.Projection; +import org.openstreetmap.josm.testutils.annotations.ThreadSync; import org.openstreetmap.josm.tools.Logging; -import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; @BasicPreferences +@Projection +@ThreadSync class HighwayNameChangeActionTest { @RegisterExtension - static JOSMTestRules rule = new JOSMTestRules().projection(); - WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")); + static WireMockExtension wireMock = WireMockExtension.newInstance() + .options(wireMockConfig().dynamicPort().dynamicHttpsPort().usingFilesUnderDirectory("test/resources/wiremock")) + .build(); + @BeforeEach void setUp() { - wireMock.start(); - Config.getPref().put("download.overpass.server", wireMock.baseUrl()); Config.getPref().putBoolean("message." + HighwayNameModification.NAME + ".downloadAdditional", false); Config.getPref().putInt("message." + HighwayNameModification.NAME + ".downloadAdditional" + ".value", JOptionPane.YES_OPTION); - } @AfterEach - void tearDown() throws ExecutionException, InterruptedException, TimeoutException { - try { - MainApplication.worker.submit(() -> { - /* Sync */}).get(10, TimeUnit.SECONDS); - } finally { - wireMock.stop(); - Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl()); - } + void tearDown() { + Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl()); } @Test diff --git a/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListenerTest.java b/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListenerTest.java index be565e6..fb51d47 100644 --- a/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListenerTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListenerTest.java @@ -1,15 +1,11 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.highwaynamemodification; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.jupiter.api.Assertions.assertTrue; import javax.swing.JOptionPane; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -19,27 +15,30 @@ import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Way; -import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.spi.preferences.Config; -import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; +import org.openstreetmap.josm.testutils.annotations.OsmApi; +import org.openstreetmap.josm.testutils.annotations.Projection; +import org.openstreetmap.josm.testutils.annotations.ThreadSync; -import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; /** * @author Ryan Fleming * */ @BasicPreferences +@Projection +@OsmApi(OsmApi.APIType.FAKE) +@ThreadSync class HighwayNameListenerTest { @RegisterExtension - static JOSMTestRules rule = new JOSMTestRules().projection().fakeAPI(); - WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")); + static WireMockExtension wireMock = WireMockExtension.newInstance() + .options(wireMockConfig().dynamicPort().dynamicHttpsPort().usingFilesUnderDirectory("test/resources/wiremock")) + .build(); @BeforeEach void setUp() { - wireMock.start(); - Config.getPref().put("download.overpass.server", wireMock.baseUrl()); Config.getPref().putBoolean("message." + HighwayNameModification.NAME + ".downloadAdditional", false); Config.getPref().putInt("message." + HighwayNameModification.NAME + ".downloadAdditional" + ".value", @@ -48,15 +47,9 @@ void setUp() { } @AfterEach - void tearDown() throws ExecutionException, InterruptedException, TimeoutException { - try { - MainApplication.worker.submit(() -> { - /* Sync thread */}).get(1, TimeUnit.MINUTES); - } finally { - wireMock.stop(); - Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl()); - Config.getPref().put("download.overpass.server", "https://overpass-api.de/api/"); - } + void tearDown() { + Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl()); + Config.getPref().put("download.overpass.server", "https://overpass-api.de/api/"); } @Test diff --git a/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameModificationTest.java b/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameModificationTest.java index b4390ff..05cd0ef 100644 --- a/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameModificationTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameModificationTest.java @@ -3,26 +3,23 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.swing.JMenu; - import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import javax.swing.JMenu; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.plugins.PluginException; import org.openstreetmap.josm.plugins.PluginInformation; -import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; +import org.openstreetmap.josm.testutils.annotations.Main; @BasicPreferences +@Main class HighwayNameModificationTest { - @RegisterExtension - static JOSMTestRules test = new JOSMTestRules().main(); - PluginInformation info; HighwayNameModification plugin;