Ignore:
Timestamp:
2021-08-01T21:21:38+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21150 - Add JUnit5 annotation for WireMockServer (patch by taylor.smock)

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java

    r17195 r18106  
    55import static com.github.tomakehurst.wiremock.client.WireMock.get;
    66import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    8 import static org.junit.Assert.assertEquals;
    9 import static org.junit.Assert.assertTrue;
     7import static org.junit.jupiter.api.Assertions.assertEquals;
     8import static org.junit.jupiter.api.Assertions.assertTrue;
    109
    1110import java.util.List;
    1211
    13 import org.junit.Rule;
    14 import org.junit.Test;
    15 import org.openstreetmap.josm.TestUtils;
     12import org.junit.jupiter.api.Test;
     13import org.junit.jupiter.api.extension.RegisterExtension;
    1614import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1715import org.openstreetmap.josm.gui.MainApplication;
     
    1917import org.openstreetmap.josm.gui.layer.WMSLayer;
    2018import org.openstreetmap.josm.testutils.JOSMTestRules;
     19import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     20import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    2121
    22 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     22import com.github.tomakehurst.wiremock.WireMockServer;
    2323
    2424import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2727 * Unit tests for class {@link AddImageryLayerAction}.
    2828 */
    29 public final class AddImageryLayerActionTest {
     29@BasicWiremock
     30@BasicPreferences
     31final class AddImageryLayerActionTest {
    3032    /**
    3133     * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
    3234     */
    33     @Rule
     35    @RegisterExtension
    3436    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    35     public JOSMTestRules test = new JOSMTestRules().preferences().fakeAPI();
     37    public JOSMTestRules test = new JOSMTestRules().fakeAPI();
    3638
    3739    /**
    3840     * HTTP mock.
    3941     */
    40     @Rule
    41     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     42    @BasicWiremock
     43    WireMockServer wireMockServer;
    4244
    4345    /**
     
    4547     */
    4648    @Test
    47     public void testEnabledState() {
     49    void testEnabledState() {
    4850        assertTrue(new AddImageryLayerAction(new ImageryInfo("foo")).isEnabled());
    4951        assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
     
    5759     */
    5860    @Test
    59     public void testActionPerformedEnabledTms() {
     61    void testActionPerformedEnabledTms() {
    6062        assertTrue(MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
    6163        new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
     
    6971     */
    7072    @Test
    71     public void testActionPerformedEnabledWms() {
    72         wireMockRule.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))
     73    void testActionPerformedEnabledWms() {
     74        wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))
    7375                .willReturn(aResponse()
    7476                        .withStatus(200)
    7577                        .withHeader("Content-Type", "text/xml")
    7678                        .withBodyFile("imagery/wms-capabilities.xml")));
    77         wireMockRule.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities"))
     79        wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities"))
    7880                .willReturn(aResponse()
    7981                        .withStatus(404)));
    80         wireMockRule.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))
     82        wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))
    8183                .willReturn(aResponse()
    8284                        .withStatus(404)));
    8385
    84         new AddImageryLayerAction(new ImageryInfo("localhost", wireMockRule.url("/wms?"),
     86        new AddImageryLayerAction(new ImageryInfo("localhost", wireMockServer.url("/wms?"),
    8587                "wms_endpoint", null, null)).actionPerformed(null);
    8688        List<WMSLayer> wmsLayers = MainApplication.getLayerManager().getLayersOfType(WMSLayer.class);
     
    9496     */
    9597    @Test
    96     public void testActionPerformedDisabled() {
     98    void testActionPerformedDisabled() {
    9799        assertTrue(MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
    98100        try {
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTaskTestParent.java

    r17195 r18106  
    55import static com.github.tomakehurst.wiremock.client.WireMock.get;
    66import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    87
    9 import org.junit.Rule;
    10 import org.openstreetmap.josm.TestUtils;
     8import org.junit.jupiter.api.extension.RegisterExtension;
    119import org.openstreetmap.josm.testutils.JOSMTestRules;
     10import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    1211
    13 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     12import com.github.tomakehurst.wiremock.WireMockServer;
    1413
    1514import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2322     * Setup test.
    2423     */
    25     @Rule
     24    @RegisterExtension
    2625    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    27     public JOSMTestRules test = new JOSMTestRules().https();
     26    JOSMTestRules test = new JOSMTestRules().https();
    2827
    2928    /**
    3029     * HTTP mock.
    3130     */
    32     @Rule
    33     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     31    @BasicWiremock
     32    WireMockServer wireMockServer;
    3433
    3534    /**
     
    5352     */
    5453    protected final String getRemoteFileUrl() {
    55         return wireMockRule.url(getRemoteFile());
     54        return wireMockServer.url(getRemoteFile());
    5655    }
    5756
     
    6059     */
    6160    protected final void mockHttp() {
    62         wireMockRule.stubFor(get(urlEqualTo("/" + getRemoteFile()))
     61        wireMockServer.stubFor(get(urlEqualTo("/" + getRemoteFile()))
    6362                .willReturn(aResponse()
    6463                    .withStatus(200)
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java

    r13927 r18106  
    22package org.openstreetmap.josm.actions.downloadtasks;
    33
    4 import static org.junit.Assert.assertFalse;
    5 import static org.junit.Assert.assertNotNull;
    6 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertFalse;
     5import static org.junit.jupiter.api.Assertions.assertNotNull;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    77
    88import java.util.concurrent.ExecutionException;
    99
    10 import org.junit.Test;
     10import org.junit.jupiter.api.Test;
    1111import org.openstreetmap.josm.data.gpx.GpxData;
     12import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    1213
    1314/**
    1415 * Unit tests for class {@link DownloadGpsTask}.
    1516 */
    16 public class DownloadGpsTaskTest extends AbstractDownloadTaskTestParent {
     17@BasicWiremock
     18class DownloadGpsTaskTest extends AbstractDownloadTaskTestParent {
    1719
    1820    /**
     
    2022     */
    2123    @Test
    22     public void testAcceptsURL() {
     24    void testAcceptsURL() {
    2325        DownloadGpsTask task = new DownloadGpsTask();
    2426        assertFalse(task.acceptsUrl(null));
     
    4244     */
    4345    @Test
    44     public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
     46    void testDownloadExternalFile() throws InterruptedException, ExecutionException {
    4547        mockHttp();
    4648        DownloadGpsTask task = new DownloadGpsTask();
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTaskTest.java

    r13927 r18106  
    22package org.openstreetmap.josm.actions.downloadtasks;
    33
    4 import static org.junit.Assert.assertFalse;
    5 import static org.junit.Assert.assertNotNull;
    6 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertFalse;
     5import static org.junit.jupiter.api.Assertions.assertNotNull;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    77
    88import java.util.concurrent.ExecutionException;
    99
    10 import org.junit.Test;
     10import org.junit.jupiter.api.Test;
    1111import org.openstreetmap.josm.data.osm.NoteData;
     12import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    1213
    1314/**
    1415 * Unit tests for class {@link DownloadNotesTask}.
    1516 */
    16 public class DownloadNotesTaskTest extends AbstractDownloadTaskTestParent {
     17@BasicWiremock
     18class DownloadNotesTaskTest extends AbstractDownloadTaskTestParent {
    1719
    1820    /**
     
    2022     */
    2123    @Test
    22     public void testAcceptsURL() {
     24    void testAcceptsURL() {
    2325        DownloadNotesTask task = new DownloadNotesTask();
    2426        assertFalse(task.acceptsUrl(null));
     
    3739     */
    3840    @Test
    39     public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
     41    void testDownloadExternalFile() throws InterruptedException, ExecutionException {
    4042        mockHttp();
    4143        DownloadNotesTask task = new DownloadNotesTask();
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java

    r13927 r18106  
    22package org.openstreetmap.josm.actions.downloadtasks;
    33
    4 import static org.junit.Assert.assertFalse;
    5 import static org.junit.Assert.assertNotNull;
    6 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertFalse;
     5import static org.junit.jupiter.api.Assertions.assertNotNull;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    77
    88import java.util.concurrent.ExecutionException;
    99
    10 import org.junit.Test;
     10import org.junit.jupiter.api.Test;
    1111import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    1213
    1314/**
    1415 * Unit tests for class {@link DownloadOsmTask}.
    1516 */
    16 public class DownloadOsmTaskTest extends AbstractDownloadTaskTestParent {
     17@BasicWiremock
     18class DownloadOsmTaskTest extends AbstractDownloadTaskTestParent {
    1719
    1820    /**
     
    2022     */
    2123    @Test
    22     public void testAcceptsURL() {
     24    void testAcceptsURL() {
    2325        DownloadOsmTask task = new DownloadOsmTask();
    2426        assertFalse(task.acceptsUrl(null));
     
    3941     */
    4042    @Test
    41     public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
     43    void testDownloadExternalFile() throws InterruptedException, ExecutionException {
    4244        mockHttp();
    4345        DownloadOsmTask task = new DownloadOsmTask();
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PluginDownloadTaskTest.java

    r16162 r18106  
    22package org.openstreetmap.josm.actions.downloadtasks;
    33
    4 import static org.junit.Assert.assertArrayEquals;
    5 import static org.junit.Assert.assertFalse;
    6 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertArrayEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    77
    88import java.io.File;
     
    1212import java.util.Collections;
    1313
    14 import org.junit.Rule;
    15 import org.junit.Test;
     14import org.junit.jupiter.api.Test;
     15import org.junit.jupiter.api.extension.RegisterExtension;
    1616import org.openstreetmap.josm.TestUtils;
    1717import org.openstreetmap.josm.data.Preferences;
     
    2020import org.openstreetmap.josm.plugins.PluginInformation;
    2121import org.openstreetmap.josm.testutils.JOSMTestRules;
     22import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     23import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    2224import org.openstreetmap.josm.tools.Utils;
    2325
     
    2729 * Unit tests for class {@link PluginDownloadTask}.
    2830 */
    29 public class PluginDownloadTaskTest extends AbstractDownloadTaskTestParent {
     31@BasicWiremock
     32@BasicPreferences
     33class PluginDownloadTaskTest extends AbstractDownloadTaskTestParent {
    3034    protected String pluginPath;
    3135
     
    3337     * Setup test.
    3438     */
    35     @Rule
     39    @RegisterExtension
    3640    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3741    public JOSMTestRules testRule = new JOSMTestRules().https().assumeRevision(
    3842        "Revision: 8000\n"
    39     ).preferences();
     43    );
    4044
    4145    @Override
     
    5559     */
    5660    @Test
    57     public void testUpdatePluginValid() throws Exception {
     61    void testUpdatePluginValid() throws Exception {
    5862        this.pluginPath = "plugin/dummy_plugin.v31772.jar";
    5963        this.mockHttp();
     
    97101     */
    98102    @Test
    99     public void testUpdatePluginCorrupt() throws Exception {
     103    void testUpdatePluginCorrupt() throws Exception {
    100104        this.pluginPath = "plugin/corrupted_plugin.jar";
    101105        this.mockHttp();
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java

    r17075 r18106  
    1010import static com.github.tomakehurst.wiremock.client.WireMock.status;
    1111import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    12 import static org.junit.Assert.assertArrayEquals;
    13 import static org.junit.Assert.assertEquals;
    14 import static org.junit.Assert.assertFalse;
    15 import static org.junit.Assert.assertTrue;
     12import static org.junit.jupiter.api.Assertions.assertArrayEquals;
     13import static org.junit.jupiter.api.Assertions.assertEquals;
     14import static org.junit.jupiter.api.Assertions.assertFalse;
     15import static org.junit.jupiter.api.Assertions.assertTrue;
    1616
    1717import java.io.IOException;
     
    2323import org.apache.commons.jcs3.access.behavior.ICacheAccess;
    2424import org.apache.commons.jcs3.engine.behavior.ICacheElement;
    25 import org.junit.Before;
    26 import org.junit.Rule;
    27 import org.junit.Test;
     25import org.junit.jupiter.api.BeforeEach;
     26import org.junit.jupiter.api.Test;
     27import org.junit.jupiter.api.Timeout;
    2828import org.openstreetmap.josm.TestUtils;
    2929import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult;
    3030import org.openstreetmap.josm.data.imagery.TileJobOptions;
    31 import org.openstreetmap.josm.testutils.JOSMTestRules;
     31import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     32import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    3233import org.openstreetmap.josm.tools.Logging;
    3334
    34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
    35 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     35import com.github.tomakehurst.wiremock.WireMockServer;
    3636import com.github.tomakehurst.wiremock.matching.UrlPattern;
    37 
    38 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3937
    4038/**
    4139 * Unit tests for class {@link JCSCachedTileLoaderJob}.
    4240 */
    43 public class JCSCachedTileLoaderJobTest {
     41@BasicWiremock
     42@BasicPreferences
     43@Timeout(20)
     44class JCSCachedTileLoaderJobTest {
    4445
    4546    /**
    4647     * mocked tile server
    4748     */
    48     @Rule
    49     public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()
    50             .dynamicPort());
     49    @BasicWiremock
     50    WireMockServer tileServer;
    5151
    5252    private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> {
     
    104104
    105105    /**
    106      * Setup test.
    107      */
    108     @Rule
    109     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    110     public JOSMTestRules test = new JOSMTestRules().preferences().timeout(20_000);
    111 
    112     /**
    113106     * Always clear cache before tests
    114107     * @throws Exception when clearing fails
    115108     */
    116     @Before
    117     public void clearCache() throws Exception {
     109    @BeforeEach
     110    void clearCache() throws Exception {
    118111        getCache().clear();
    119112    }
     
    125118     */
    126119    @Test
    127     public void testStatusCodes() throws IOException, InterruptedException {
     120    void testStatusCodes() throws IOException, InterruptedException {
    128121        doTestStatusCode(200);
    129122        doTestStatusCode(401);
     
    142135     */
    143136    @Test
    144     public void testUnknownHost() throws IOException {
     137    void testUnknownHost() throws IOException {
    145138        String key = "key_unknown_host";
    146139        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key);
     
    193186     */
    194187    @Test
    195     public void testNoRequestMadeWhenEntryInCache() throws IOException {
     188    void testNoRequestMadeWhenEntryInCache() throws IOException {
    196189        ICacheAccess<String, CacheEntry> cache = getCache();
    197190        long expires = TimeUnit.DAYS.toMillis(1);
     
    214207     */
    215208    @Test
    216     public void testRequestMadeWhenEntryInCacheAndForce() throws IOException {
     209    void testRequestMadeWhenEntryInCacheAndForce() throws IOException {
    217210        ICacheAccess<String, CacheEntry> cache = getCache();
    218211        long expires = TimeUnit.DAYS.toMillis(1);
     
    236229     */
    237230    @Test
    238     public void testSettingMinimumExpiryWhenNoExpires() throws IOException {
     231    void testSettingMinimumExpiryWhenNoExpires() throws IOException {
    239232        long testStart = System.currentTimeMillis();
    240233        tileServer.stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withBody("mock entry")));
     
    244237        tileServer.verify(1, getRequestedFor(urlEqualTo("/test")));
    245238
    246         assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
    247                 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)",
    248                 listener.attributes.getExpirationTime() >= testStart + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME);
    249 
    250         assertTrue("Cache entry expiration is " +
    251                 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
    252                 " which is not less than " +
    253                 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)",
    254                 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME
     239        assertTrue(listener.attributes.getExpirationTime() >= testStart + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME,
     240                "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
     241                        JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)");
     242
     243        assertTrue(listener.attributes.getExpirationTime() <= System.currentTimeMillis() + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME,
     244                "Cache entry expiration is " +
     245                        (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
     246                        " which is not less than " +
     247                        JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)"
    255248                );
    256249
     
    264257     */
    265258    @Test
    266     public void testSettingExpireByMaxAge() throws IOException {
     259    void testSettingExpireByMaxAge() throws IOException {
    267260        long testStart = System.currentTimeMillis();
    268261        long expires = TimeUnit.DAYS.toSeconds(1);
     
    278271        tileServer.verify(1, getRequestedFor(urlEqualTo("/test")));
    279272
    280         assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
    281                 TimeUnit.SECONDS.toMillis(expires) + " (max-age)",
    282                 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(expires));
    283 
    284         assertTrue("Cache entry expiration is " +
    285                 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
    286                 " which is not less than " +
    287                 TimeUnit.SECONDS.toMillis(expires) + " (max-age)",
    288                 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expires)
    289                 );
     273        assertTrue(listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(expires),
     274                "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
     275                        TimeUnit.SECONDS.toMillis(expires) + " (max-age)");
     276
     277        assertTrue(
     278                listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expires),
     279                "Cache entry expiration is " +
     280                        (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
     281                        " which is not less than " +
     282                        TimeUnit.SECONDS.toMillis(expires) + " (max-age)"
     283                        );
    290284
    291285        assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data);
     
    298292     */
    299293    @Test
    300     public void testSettingMinimumExpiryByMinimumExpiryTimeLessThanDefault() throws IOException {
     294    void testSettingMinimumExpiryByMinimumExpiryTimeLessThanDefault() throws IOException {
    301295        long testStart = System.currentTimeMillis();
    302296        int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2);
     
    310304
    311305
    312         assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
    313                 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)",
    314                 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds));
    315 
    316         assertTrue("Cache entry expiration is " +
    317                 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
    318                 " which is not less than " +
    319                 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)",
    320                 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)
    321                 );
     306        assertTrue(
     307                listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds),
     308                "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
     309                        TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)");
     310
     311        assertTrue(
     312                listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds),
     313                "Cache entry expiration is " +
     314                        (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
     315                        " which is not less than " +
     316                        TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)"
     317                        );
    322318    }
    323319
     
    329325
    330326    @Test
    331     public void testSettingMinimumExpiryByMinimumExpiryTimeGreaterThanDefault() throws IOException {
     327    void testSettingMinimumExpiryByMinimumExpiryTimeGreaterThanDefault() throws IOException {
    332328        long testStart = System.currentTimeMillis();
    333329        int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME * 2);
     
    341337
    342338
    343         assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
    344                 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)",
    345                 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds));
    346 
    347         assertTrue("Cache entry expiration is " +
    348                 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
    349                 " which is not less than " +
    350                 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)",
    351                 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)
    352                 );
     339        assertTrue(
     340                listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds),
     341                "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
     342                        TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)");
     343
     344        assertTrue(
     345                listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds),
     346                "Cache entry expiration is " +
     347                        (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
     348                        " which is not less than " +
     349                        TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)"
     350                        );
    353351    }
    354352
     
    365363
    366364    @Test
    367     public void testCacheControlVsExpires() throws IOException {
     365    void testCacheControlVsExpires() throws IOException {
    368366        long testStart = System.currentTimeMillis();
    369367        int minimumExpiryTimeSeconds = 0;
     
    390388
    391389
    392         assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
    393                 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Expires header)",
    394                 listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10));
    395 
    396         assertTrue("Cache entry expiration is " +
    397                 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
    398                 " which is not less than " +
    399                 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: max-age=)",
    400                 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2)
    401                 );
     390        assertTrue(
     391                listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10),
     392                "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
     393                        (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Expires header)");
     394
     395        assertTrue(listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2),
     396                "Cache entry expiration is " +
     397                        (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
     398                        " which is not less than " +
     399                        (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: max-age=)"
     400                        );
    402401    }
    403402
     
    410409     */
    411410    @Test
    412     public void testMaxAgeVsSMaxAge() throws IOException {
     411    void testMaxAgeVsSMaxAge() throws IOException {
    413412        long testStart = System.currentTimeMillis();
    414413        int minimumExpiryTimeSeconds = 0;
     
    435434        assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data);
    436435
    437         assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
    438                 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Cache-Control: max-age)",
    439                 listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10));
    440 
    441         assertTrue("Cache entry expiration is " +
    442                 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
    443                 " which is not less than " +
    444                 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: s-max-age)",
    445                 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2)
    446                 );
     436        assertTrue(
     437                listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10),
     438                "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +
     439                        (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Cache-Control: max-age)");
     440
     441        assertTrue(listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2),
     442                "Cache entry expiration is " +
     443                        (listener.attributes.getExpirationTime() - System.currentTimeMillis()) +
     444                        " which is not less than " +
     445                        (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: s-max-age)"
     446                        );
    447447    }
    448448
     
    452452     */
    453453    @Test
    454     public void testCheckUsingHead() throws IOException {
     454    void testCheckUsingHead() throws IOException {
    455455        ICacheAccess<String, CacheEntry> cache = getCache();
    456456        long expires = TimeUnit.DAYS.toMillis(1);
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java

    r16913 r18106  
    22package org.openstreetmap.josm.data.imagery;
    33
    4 import static org.junit.Assert.assertArrayEquals;
    5 import static org.junit.Assert.assertEquals;
    6 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertArrayEquals;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    77
    88import java.io.IOException;
     
    1717
    1818import org.apache.commons.jcs3.access.behavior.ICacheAccess;
    19 import org.junit.Before;
    20 import org.junit.Rule;
    21 import org.junit.Test;
     19import org.junit.jupiter.api.BeforeEach;
     20import org.junit.jupiter.api.Test;
    2221import org.openstreetmap.gui.jmapviewer.Tile;
    2322import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
     
    2726import org.openstreetmap.josm.data.cache.CacheEntryAttributes;
    2827import org.openstreetmap.josm.data.cache.JCSCacheManager;
    29 import org.openstreetmap.josm.testutils.JOSMTestRules;
     28import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     29import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    3030import org.openstreetmap.josm.tools.Logging;
    3131import org.openstreetmap.josm.tools.Utils;
    3232
     33import com.github.tomakehurst.wiremock.WireMockServer;
    3334import com.github.tomakehurst.wiremock.client.WireMock;
    34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
    35 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    36 
    37 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3835
    3936/**
    4037 * Unit tests for class {@link TMSCachedTileLoaderJob}.
    4138 */
    42 public class TMSCachedTileLoaderJobTest {
    43 
    44     /**
    45      * Setup tests
    46      */
    47     @Rule
    48     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    49     public JOSMTestRules test = new JOSMTestRules().preferences();
    50 
     39@BasicWiremock
     40@BasicPreferences
     41class TMSCachedTileLoaderJobTest {
    5142    /**
    5243     * mocked tile server
    5344     */
    54     @Rule
    55     public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()
    56             .dynamicPort());
    57 
    58     @Before
    59     public void clearCache() throws Exception {
     45    @BasicWiremock
     46    WireMockServer tileServer;
     47
     48    @BeforeEach
     49    void clearCache() throws Exception {
    6050        getCache().clear();
    6151    }
     
    145135     */
    146136    @Test
    147     public void testServiceExceptionPattern() {
     137    void testServiceExceptionPattern() {
    148138        testServiceException("missing parameters ['version', 'format']",
    149139                "<?xml version=\"1.0\"?>\n" +
     
    167157     */
    168158    @Test
    169     public void testCdataPattern() {
     159    void testCdataPattern() {
    170160        testCdata("received unsuitable wms request: no <grid> with suitable srs found for layer capitais",
    171161                "<![CDATA[\r\n" +
     
    178168     */
    179169    @Test
    180     public void testJsonPattern() {
     170    void testJsonPattern() {
    181171        testJson("Tile does not exist",
    182172                "{\"message\":\"Tile does not exist\"}");
     
    197187    private static void test(Pattern pattern, String expected, String text) {
    198188        Matcher m = pattern.matcher(text);
    199         assertTrue(text, m.matches());
     189        assertTrue(m.matches(), text);
    200190        assertEquals(expected, Utils.strip(m.group(1)));
    201191    }
     
    227217     */
    228218    @Test
    229     public void testNoCacheHeaders() throws IOException {
     219    void testNoCacheHeaders() throws IOException {
    230220        long testStart = System.currentTimeMillis();
    231221        tileServer.stubFor(
     
    250240     */
    251241    @Test
    252     public void testNoCacheHeadersMinimumExpires() throws IOException {
     242    void testNoCacheHeadersMinimumExpires() throws IOException {
    253243        noCacheHeadersMinimumExpires((int) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get() * 2));
    254244    }
     
    261251
    262252    @Test
    263     public void testNoCacheHeadersMinimumExpiresLargerThanMaximum() throws IOException {
     253    void testNoCacheHeadersMinimumExpiresLargerThanMaximum() throws IOException {
    264254        noCacheHeadersMinimumExpires((int) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MAXIMUM_EXPIRES.get() * 2));
    265255    }
     
    287277     */
    288278    @Test
    289     public void testShortExpire() throws IOException {
     279    void testShortExpire() throws IOException {
    290280        long testStart = System.currentTimeMillis();
    291281        long expires = TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get() / 2;
     
    307297
    308298    private void assertExpirationAtLeast(long duration, TestCachedTileLoaderJob job) {
    309         assertTrue(
    310                 "Expiration time shorter by " +
    311                         -1 * (job.getAttributes().getExpirationTime() - duration) +
    312                         " than expected",
    313                 job.getAttributes().getExpirationTime() >= duration);
     299        assertTrue(job.getAttributes().getExpirationTime() >= duration, "Expiration time shorter by " +
     300                                -1 * (job.getAttributes().getExpirationTime() - duration) +
     301                                " than expected");
    314302    }
    315303
    316304    private void assertExpirationAtMost(long duration, TestCachedTileLoaderJob job) {
    317         assertTrue(
    318                 "Expiration time longer by " +
    319                         (job.getAttributes().getExpirationTime() - duration) +
    320                         " than expected",
    321                 job.getAttributes().getExpirationTime() <= duration);
    322     }
    323 
    324     @Test
    325     public void testLongExpire() throws IOException {
     305        assertTrue(job.getAttributes().getExpirationTime() <= duration, "Expiration time longer by " +
     306                                (job.getAttributes().getExpirationTime() - duration) +
     307                                " than expected");
     308    }
     309
     310    @Test
     311    void testLongExpire() throws IOException {
    326312        long testStart = System.currentTimeMillis();
    327313        long expires = TMSCachedTileLoaderJob.MAXIMUM_EXPIRES.get() * 2;
     
    343329        assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent());
    344330    }
    345 
    346331}
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java

    r16636 r18106  
    22package org.openstreetmap.josm.data.imagery;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertTrue;
    66
    77import java.nio.file.Files;
     
    99import java.util.Arrays;
    1010
    11 import org.junit.Rule;
    12 import org.junit.Test;
     11import org.junit.jupiter.api.Test;
     12import org.junit.jupiter.api.extension.RegisterExtension;
    1313import org.openstreetmap.josm.TestUtils;
    1414import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
     
    1717import org.openstreetmap.josm.spi.preferences.Config;
    1818import org.openstreetmap.josm.testutils.JOSMTestRules;
     19import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    1920
     21import com.github.tomakehurst.wiremock.WireMockServer;
    2022import com.github.tomakehurst.wiremock.client.WireMock;
    21 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
    22 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    2323
    2424import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2525
    26 public class WMSEndpointTileSourceTest {
     26@BasicWiremock
     27class WMSEndpointTileSourceTest {
    2728    /**
    2829     * Setup test
    2930     */
    30     @Rule
     31    @RegisterExtension
    3132    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3233    public JOSMTestRules test = new JOSMTestRules().projection();
    3334
    34     @Rule
    35     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    36     public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
     35    @BasicWiremock
     36    WireMockServer tileServer;
    3737
    3838    @Test
    39     public void testDefaultLayerSetInMaps() throws Exception {
     39    void testDefaultLayerSetInMaps() throws Exception {
    4040
    4141        tileServer.stubFor(
     
    8787
    8888    @Test
    89     public void testCustomHeaders() throws Exception {
     89    void testCustomHeaders() throws Exception {
    9090        tileServer.stubFor(
    9191                WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r17549 r18106  
    22package org.openstreetmap.josm.data.imagery;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertTrue;
    66
    77import java.io.File;
     
    1515import java.util.concurrent.TimeUnit;
    1616
    17 import org.junit.ClassRule;
    18 import org.junit.Ignore;
    19 import org.junit.Rule;
    20 import org.junit.Test;
     17import org.junit.jupiter.api.Disabled;
     18import org.junit.jupiter.api.Test;
     19import org.junit.jupiter.api.extension.RegisterExtension;
    2120import org.openstreetmap.gui.jmapviewer.TileXY;
    2221import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
     
    3029import org.openstreetmap.josm.spi.preferences.Config;
    3130import org.openstreetmap.josm.testutils.JOSMTestRules;
    32 
     31import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     32import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     33
     34import com.github.tomakehurst.wiremock.WireMockServer;
    3335import com.github.tomakehurst.wiremock.client.WireMock;
    34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
    35 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    3636
    3737import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    4040 * Unit tests for class {@link WMTSTileSource}.
    4141 */
    42 public class WMTSTileSourceTest {
     42@BasicWiremock
     43@BasicPreferences
     44class WMTSTileSourceTest {
    4345
    4446    /**
    4547     * Setup test.
    4648     */
    47     @ClassRule
     49    @RegisterExtension
    4850    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    49     public static JOSMTestRules test = new JOSMTestRules().preferences().projection().timeout((int) TimeUnit.MINUTES.toMillis(5));
    50 
    51     @Rule
    52     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    53     public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
     51    public static JOSMTestRules test = new JOSMTestRules().projection().timeout((int) TimeUnit.MINUTES.toMillis(5));
     52
     53    @BasicWiremock
     54    WireMockServer tileServer;
    5455
    5556    private final ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
     
    8687
    8788    @Test
    88     public void testPseudoMercator() throws IOException, WMTSGetCapabilitiesException {
     89    void testPseudoMercator() throws IOException, WMTSGetCapabilitiesException {
    8990        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    9091        WMTSTileSource testSource = new WMTSTileSource(testImageryPSEUDO_MERCATOR);
     
    107108        verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 10);
    108109
    109         assertEquals("TileXMax", 1, testSource.getTileXMax(0));
    110         assertEquals("TileYMax", 1, testSource.getTileYMax(0));
    111         assertEquals("TileXMax", 2, testSource.getTileXMax(1));
    112         assertEquals("TileYMax", 2, testSource.getTileYMax(1));
    113         assertEquals("TileXMax", 4, testSource.getTileXMax(2));
    114         assertEquals("TileYMax", 4, testSource.getTileYMax(2));
    115     }
    116 
    117     @Test
    118     public void testWALLONIE() throws IOException, WMTSGetCapabilitiesException {
     110        assertEquals(1, testSource.getTileXMax(0), "TileXMax");
     111        assertEquals(1, testSource.getTileYMax(0), "TileYMax");
     112        assertEquals(2, testSource.getTileXMax(1), "TileXMax");
     113        assertEquals(2, testSource.getTileYMax(1), "TileYMax");
     114        assertEquals(4, testSource.getTileXMax(2), "TileXMax");
     115        assertEquals(4, testSource.getTileYMax(2), "TileYMax");
     116    }
     117
     118    @Test
     119    void testWALLONIE() throws IOException, WMTSGetCapabilitiesException {
    119120        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:31370"));
    120121        WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE);
     
    135136
    136137    @Test
    137     @Ignore("disable this test, needs further working") // XXX
    138     public void testWALLONIENoMatrixDimension() throws IOException, WMTSGetCapabilitiesException {
     138    @Disabled("disable this test, needs further working") // XXX
     139    void testWALLONIENoMatrixDimension() throws IOException, WMTSGetCapabilitiesException {
    139140        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:31370"));
    140141        WMTSTileSource testSource = new WMTSTileSource(getImagery("test/data/wmts/WMTSCapabilities-Wallonie-nomatrixdimension.xml"));
     
    152153    private void verifyBounds(Bounds bounds, WMTSTileSource testSource, int z, int x, int y) {
    153154        LatLon ret = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z));
    154         assertTrue(ret.toDisplayString() + " doesn't lie within: " + bounds.toString(), bounds.contains(ret));
     155        assertTrue(bounds.contains(ret), ret.toDisplayString() + " doesn't lie within: " + bounds);
    155156        int tileXmax = testSource.getTileXMax(z);
    156157        int tileYmax = testSource.getTileYMax(z);
    157         assertTrue("tile x: " + x + " is greater than allowed max: " + tileXmax, tileXmax >= x);
    158         assertTrue("tile y: " + y + " is greater than allowed max: " + tileYmax, tileYmax >= y);
    159     }
    160 
    161     @Test
    162     public void testWIEN() throws IOException, WMTSGetCapabilitiesException {
     158        assertTrue(tileXmax >= x, "tile x: " + x + " is greater than allowed max: " + tileXmax);
     159        assertTrue(tileYmax >= y, "tile y: " + y + " is greater than allowed max: " + tileYmax);
     160    }
     161
     162    @Test
     163    void testWIEN() throws IOException, WMTSGetCapabilitiesException {
    163164        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    164165        WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN);
     
    195196        int result = testSource.getTileXMax(zoom);
    196197        int expected = verifier.getTileXMax(zoom + zoomOffset);
    197         assertTrue("TileXMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
     198        assertTrue(Math.abs(result - expected) < 5, "TileXMax expected: " + expected + " got: " + result);
    198199        result = testSource.getTileYMax(zoom);
    199200        expected = verifier.getTileYMax(zoom + zoomOffset);
    200         assertTrue("TileYMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
    201     }
    202 
    203     @Test
    204     public void testGeoportalTOPOPL() throws IOException, WMTSGetCapabilitiesException {
     201        assertTrue(Math.abs(result - expected) < 5, "TileYMax expected: " + expected + " got: " + result);
     202    }
     203
     204    @Test
     205    void testGeoportalTOPOPL() throws IOException, WMTSGetCapabilitiesException {
    205206        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:4326"));
    206207        WMTSTileSource testSource = new WMTSTileSource(testImageryTOPO_PL);
     
    210211        verifyTile(new LatLon(51.13231917844218, 16.867680821557823), testSource, 1, 1, 1);
    211212
    212         assertEquals("TileXMax", 2, testSource.getTileXMax(0));
    213         assertEquals("TileYMax", 1, testSource.getTileYMax(0));
    214         assertEquals("TileXMax", 3, testSource.getTileXMax(1));
    215         assertEquals("TileYMax", 2, testSource.getTileYMax(1));
    216         assertEquals("TileXMax", 6, testSource.getTileXMax(2));
    217         assertEquals("TileYMax", 4, testSource.getTileYMax(2));
     213        assertEquals(2, testSource.getTileXMax(0), "TileXMax");
     214        assertEquals(1, testSource.getTileYMax(0), "TileYMax");
     215        assertEquals(3, testSource.getTileXMax(1), "TileXMax");
     216        assertEquals(2, testSource.getTileYMax(1), "TileYMax");
     217        assertEquals(6, testSource.getTileXMax(2), "TileXMax");
     218        assertEquals(4, testSource.getTileYMax(2), "TileYMax");
    218219        assertEquals(
    219220                "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/TOPO?SERVICE=WMTS&REQUEST=GetTile&"
     
    224225
    225226    @Test
    226     public void testGeoportalORTOPL4326() throws IOException, WMTSGetCapabilitiesException {
     227    void testGeoportalORTOPL4326() throws IOException, WMTSGetCapabilitiesException {
    227228        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:4326"));
    228229        WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
     
    233234
    234235    @Test
    235     public void testGeoportalORTOPL2180() throws IOException, WMTSGetCapabilitiesException {
     236    void testGeoportalORTOPL2180() throws IOException, WMTSGetCapabilitiesException {
    236237        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:2180"));
    237238        WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
     
    243244
    244245    @Test
    245     public void testTicket12168() throws IOException, WMTSGetCapabilitiesException {
     246    void testTicket12168() throws IOException, WMTSGetCapabilitiesException {
    246247        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    247248        WMTSTileSource testSource = new WMTSTileSource(testImagery12168);
     
    253254
    254255    @Test
    255     public void testProjectionWithENUAxis() throws IOException, WMTSGetCapabilitiesException {
     256    void testProjectionWithENUAxis() throws IOException, WMTSGetCapabilitiesException {
    256257        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3346"));
    257258        WMTSTileSource testSource = new WMTSTileSource(testImageryORT2LT);
     
    267268
    268269    @Test
    269     public void testTwoTileSetsForOneProjection() throws Exception {
     270    void testTwoTileSetsForOneProjection() throws Exception {
    270271        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    271272        ImageryInfo ontario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
     
    284285
    285286    @Test
    286     public void testTwoTileSetsForOneProjectionSecondLayer() throws Exception {
     287    void testTwoTileSetsForOneProjectionSecondLayer() throws Exception {
    287288        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    288289        ImageryInfo ontario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
     
    301302
    302303    @Test
    303     public void testManyLayersScrollbars() throws Exception {
     304    void testManyLayersScrollbars() throws Exception {
    304305        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    305306        WMTSTileSource testSource = new WMTSTileSource(testLotsOfLayers);
     
    308309
    309310    @Test
    310     public void testParserForDuplicateTags() throws Exception {
     311    void testParserForDuplicateTags() throws Exception {
    311312        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    312313        WMTSTileSource testSource = new WMTSTileSource(testDuplicateTags);
     
    320321
    321322    @Test
    322     public void testParserForMissingStyleIdentifier() throws Exception {
     323    void testParserForMissingStyleIdentifier() throws Exception {
    323324        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    324325        WMTSTileSource testSource = new WMTSTileSource(testMissingStyleIdentifier);
     
    327328
    328329    @Test
    329     public void testForMultipleTileMatricesForOneLayerProjection() throws Exception {
     330    void testForMultipleTileMatricesForOneLayerProjection() throws Exception {
    330331        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    331332        ImageryInfo copy = new ImageryInfo(testMultipleTileMatrixForLayer);
     
    348349     */
    349350    @Test
    350     public void testDimension() throws IOException, WMTSGetCapabilitiesException {
     351    void testDimension() throws IOException, WMTSGetCapabilitiesException {
    351352        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:21781"));
    352353        ImageryInfo info = new ImageryInfo(testImageryGeoAdminCh);
     
    363364
    364365    @Test
    365     public void testDefaultLayer() throws Exception {
     366    void testDefaultLayer() throws Exception {
    366367        // https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/1.0.0/WMTSCapabilities.xml
    367368        // do not use withFileBody as it needs different directory layout :(
     
    412413    private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) {
    413414        LatLon ll = CoordinateConversion.coorToLL(source.tileXYToLatLon(x, y, z));
    414         assertEquals("Latitude", expected.lat(), ll.lat(), 1e-05);
    415         assertEquals("Longitude", expected.lon(), ll.lon(), 1e-05);
     415        assertEquals(expected.lat(), ll.lat(), 1e-05, "Latitude");
     416        assertEquals(expected.lon(), ll.lon(), 1e-05, "Longitude");
    416417    }
    417418
     
    424425        LatLon result = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z));
    425426        LatLon expected = CoordinateConversion.coorToLL(verifier.tileXYToLatLon(x, y, z + zoomOffset));
    426         assertEquals("Longitude", LatLon.normalizeLon(expected.lon() - result.lon()), 0.0, 1e-04);
    427         assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
    428     }
    429 
    430     @Test
    431     public void testGisKtnGvAt() throws IOException, WMTSGetCapabilitiesException {
     427        assertEquals(0.0, LatLon.normalizeLon(expected.lon() - result.lon()), 1e-04, "Longitude");
     428        assertEquals(expected.lat(), result.lat(), 1e-04, "Latitude");
     429    }
     430
     431    @Test
     432    void testGisKtnGvAt() throws IOException, WMTSGetCapabilitiesException {
    432433        ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:31258"));
    433434        final WMTSTileSource source = new WMTSTileSource(testImageryGisKtnGvAt);
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DefaultNameFormatterTest.java

    r17673 r18106  
    55import static com.github.tomakehurst.wiremock.client.WireMock.get;
    66import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    8 import static org.junit.Assert.assertEquals;
     7import static org.junit.jupiter.api.Assertions.assertEquals;
    98
    109import java.io.IOException;
     
    1615import java.util.stream.IntStream;
    1716
    18 import org.junit.Rule;
    19 import org.junit.Test;
     17import org.junit.jupiter.api.Test;
    2018import org.openstreetmap.josm.TestUtils;
    2119import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
     
    2321import org.openstreetmap.josm.io.IllegalDataException;
    2422import org.openstreetmap.josm.io.OsmReader;
    25 import org.openstreetmap.josm.testutils.JOSMTestRules;
     23import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     24import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     25import org.openstreetmap.josm.testutils.annotations.HTTP;
    2626import org.xml.sax.SAXException;
    2727
    28 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     28import com.github.tomakehurst.wiremock.WireMockServer;
    2929
    3030import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    3333 * Unit tests of {@link DefaultNameFormatter} class.
    3434 */
    35 public class DefaultNameFormatterTest {
    36 
    37     /**
    38      * Setup test.
    39      */
    40     @Rule
    41     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    42     public JOSMTestRules test = new JOSMTestRules();
    43 
     35// Preferences are needed for OSM primitives
     36@BasicPreferences
     37@BasicWiremock
     38@HTTP
     39class DefaultNameFormatterTest {
    4440    /**
    4541     * HTTP mock.
    4642     */
    47     @Rule
    48     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     43    @BasicWiremock
     44    WireMockServer wireMockServer;
    4945
    5046    /**
     
    5652    @Test
    5753    @SuppressFBWarnings(value = "ITA_INEFFICIENT_TO_ARRAY")
    58     public void testTicket9632() throws IllegalDataException, IOException, SAXException {
     54    void testTicket9632() throws IllegalDataException, IOException, SAXException {
    5955        String source = "presets/Presets_BicycleJunction-preset.xml";
    60         wireMockRule.stubFor(get(urlEqualTo("/" + source))
     56        wireMockServer.stubFor(get(urlEqualTo("/" + source))
    6157                .willReturn(aResponse()
    6258                    .withStatus(200)
    6359                    .withHeader("Content-Type", "text/xml")
    6460                    .withBodyFile(source)));
    65         TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(wireMockRule.url(source), true));
     61        TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(wireMockServer.url(source), true));
    6662
    6763        Comparator<IRelation<?>> comparator = DefaultNameFormatter.getInstance().getRelationComparator();
     
    10298     */
    10399    @Test
    104     public void testRelationName() {
     100    void testRelationName() {
    105101        assertEquals("relation (0, 0 members)",
    106102                getFormattedRelationName("X=Y"));
     
    123119     */
    124120    @Test
    125     public void testWayName() {
     121    void testWayName() {
    126122        assertEquals("\u200Ebuilding\u200E (0 nodes)\u200C", getFormattedWayName("building=yes"));
    127123        assertEquals("\u200EHouse number 123\u200E (0 nodes)\u200C",
     
    145141     */
    146142    @Test
    147     public void testFormatAsHtmlUnorderedList() {
     143    void testFormatAsHtmlUnorderedList() {
    148144        assertEquals("<ul><li>incomplete</li></ul>",
    149145                DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(new Node(1)));
     
    159155     */
    160156    @Test
    161     public void testBuildDefaultToolTip() {
     157    void testBuildDefaultToolTip() {
    162158        assertEquals("<html><strong>id</strong>=0<br>"+
    163159                           "<strong>name:en</strong>=foo<br>"+
     
    173169     */
    174170    @Test
    175     public void testRemoveBiDiCharacters() {
     171    void testRemoveBiDiCharacters() {
    176172        assertEquals("building (0 nodes)", DefaultNameFormatter.removeBiDiCharacters("\u200Ebuilding\u200E (0 nodes)\u200C"));
    177173    }
  • trunk/test/unit/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClientTest.java

    r17196 r18106  
    55import static com.github.tomakehurst.wiremock.client.WireMock.get;
    66import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    8 import static org.junit.Assert.assertEquals;
    9 import static org.junit.Assert.assertNotNull;
    10 import static org.junit.Assert.assertNull;
     7import static org.junit.jupiter.api.Assertions.assertEquals;
     8import static org.junit.jupiter.api.Assertions.assertNotNull;
     9import static org.junit.jupiter.api.Assertions.assertNull;
    1110
    1211import java.net.CookieHandler;
     
    1514import java.util.Collections;
    1615
    17 import org.junit.Rule;
    18 import org.junit.Test;
     16import org.junit.jupiter.api.Test;
     17import org.junit.jupiter.api.Timeout;
    1918import org.openstreetmap.josm.data.oauth.OAuthParameters;
    2019import org.openstreetmap.josm.data.oauth.OAuthToken;
    2120import org.openstreetmap.josm.io.OsmTransferCanceledException;
    22 import org.openstreetmap.josm.testutils.JOSMTestRules;
     21import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     22import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     23import org.openstreetmap.josm.testutils.annotations.HTTP;
    2324
    24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    25 
    26 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     25import com.github.tomakehurst.wiremock.WireMockServer;
    2726
    2827/**
    2928 * Unit tests of {@link OsmOAuthAuthorizationClient} class.
    3029 */
    31 public class OsmOAuthAuthorizationClientTest {
    32 
    33     /**
    34      * Setup tests
    35      */
    36     @Rule
    37     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    38     public JOSMTestRules test = new JOSMTestRules().timeout(20000);
    39 
     30@Timeout(20)
     31@BasicWiremock
     32// Needed for OAuthParameters
     33@BasicPreferences
     34@HTTP
     35class OsmOAuthAuthorizationClientTest {
    4036    /**
    4137     * HTTP mock.
    4238     */
    43     @Rule
    44     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
     39    @BasicWiremock
     40    WireMockServer wireMockServer;
    4541
    4642    /**
     
    5046     */
    5147    @Test
    52     public void testOsmOAuthAuthorizationClient() throws OsmTransferCanceledException, OsmOAuthAuthorizationException {
     48    void testOsmOAuthAuthorizationClient() throws OsmTransferCanceledException, OsmOAuthAuthorizationException {
    5349        // request token
    54         wireMockRule.stubFor(get(urlEqualTo("/oauth/request_token"))
     50        wireMockServer.stubFor(get(urlEqualTo("/oauth/request_token"))
    5551                .willReturn(aResponse().withStatus(200).withBody(String.join("&",
    5652                        "oauth_token=entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR",
    5753                        "oauth_token_secret=nsBD2Hr5lLGDUeNoh3SnLaGsUV1TiPYM4qUr7tPB"))));
    58         OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(OAuthParameters.createDefault(wireMockRule.url("/api")));
     54        OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(OAuthParameters.createDefault(
     55                wireMockServer.url("/api")));
    5956
    6057        OAuthToken requestToken = client.getRequestToken(null);
    61         assertEquals("requestToken.key", "entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR", requestToken.getKey());
    62         assertEquals("requestToken.secret", "nsBD2Hr5lLGDUeNoh3SnLaGsUV1TiPYM4qUr7tPB", requestToken.getSecret());
     58        assertEquals("entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR", requestToken.getKey(), "requestToken.key");
     59        assertEquals("nsBD2Hr5lLGDUeNoh3SnLaGsUV1TiPYM4qUr7tPB", requestToken.getSecret(), "requestToken.secret");
    6360        String url = client.getAuthoriseUrl(requestToken);
    64         assertEquals("url", wireMockRule.url("/oauth/authorize?oauth_token=entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR"), url);
     61        assertEquals(wireMockServer.url("/oauth/authorize?oauth_token=entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR"), url, "url");
    6562
    6663        // access token
    67         wireMockRule.stubFor(get(urlEqualTo("/oauth/access_token"))
     64        wireMockServer.stubFor(get(urlEqualTo("/oauth/access_token"))
    6865                .willReturn(aResponse().withStatus(200).withBody(String.join("&",
    6966                        "oauth_token=eGMGmosXuiChRntxUGuwRKV6KyVDF0OWScdGhbqX",
     
    7168
    7269        OAuthToken accessToken = client.getAccessToken(null);
    73         assertEquals("accessToken.key", "eGMGmosXuiChRntxUGuwRKV6KyVDF0OWScdGhbqX", accessToken.getKey());
    74         assertEquals("accessToken.secret", "nsBUeNor7tPh3SHr5lLaGsGDUD2PYMV1TinL4qUB", accessToken.getSecret());
     70        assertEquals("eGMGmosXuiChRntxUGuwRKV6KyVDF0OWScdGhbqX", accessToken.getKey(), "accessToken.key");
     71        assertEquals("nsBUeNor7tPh3SHr5lLaGsGDUD2PYMV1TinL4qUB", accessToken.getSecret(), "accessToken.secret");
    7572    }
    7673
     
    8279     */
    8380    @Test
    84     public void testCookieHandlingMock() throws Exception {
    85         wireMockRule.stubFor(get(urlEqualTo("/login?cookie_test=true"))
     81    void testCookieHandlingMock() throws Exception {
     82        wireMockServer.stubFor(get(urlEqualTo("/login?cookie_test=true"))
    8683                .willReturn(aResponse()
    8784                        .withStatus(200)
     
    9087                        "name=\"authenticity_token\" " +
    9188                        "value=\"fzp6CWJhp6Vns09re3s2Tw==\" />")));
    92         final OAuthParameters parameters = OAuthParameters.createDefault(wireMockRule.url("/api"));
     89        final OAuthParameters parameters = OAuthParameters.createDefault(wireMockServer.url("/api"));
    9390        final OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(parameters);
    9491        final OsmOAuthAuthorizationClient.SessionId sessionId = client.fetchOsmWebsiteSessionId();
    9592        assertNotNull(sessionId);
    96         assertEquals("sessionId.id", "7fe8e2ea36c6b803cb902301b28e0a", sessionId.id);
    97         assertEquals("sessionId.token", "fzp6CWJhp6Vns09re3s2Tw==", sessionId.token);
    98         assertNull("sessionId.userName", sessionId.userName);
     93        assertEquals("7fe8e2ea36c6b803cb902301b28e0a", sessionId.id, "sessionId.id");
     94        assertEquals("fzp6CWJhp6Vns09re3s2Tw==", sessionId.token, "sessionId.token");
     95        assertNull(sessionId.userName, "sessionId.userName");
    9996    }
    10097
     
    106103     */
    107104    @Test
    108     public void testCookieHandlingCookieManager() throws Exception {
     105    void testCookieHandlingCookieManager() throws Exception {
    109106        // emulate Java Web Start behaviour
    110107        // see https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTaskTest.java

    r17194 r18106  
    55import static com.github.tomakehurst.wiremock.client.WireMock.get;
    66import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    87import static org.hamcrest.CoreMatchers.containsString;
    98import static org.hamcrest.MatcherAssert.assertThat;
    10 import static org.junit.Assert.assertFalse;
    11 import static org.junit.Assert.assertTrue;
     9import static org.junit.jupiter.api.Assertions.assertFalse;
     10import static org.junit.jupiter.api.Assertions.assertThrows;
     11import static org.junit.jupiter.api.Assertions.assertTrue;
    1212
     13import javax.swing.JLabel;
    1314import java.awt.Component;
    1415
    15 import javax.swing.JLabel;
    16 
    17 import org.junit.Rule;
    18 import org.junit.Test;
    19 import org.openstreetmap.josm.TestUtils;
    20 import org.openstreetmap.josm.testutils.JOSMTestRules;
     16import org.junit.jupiter.api.Test;
     17import org.junit.jupiter.api.Timeout;
     18import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     19import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     20import org.openstreetmap.josm.testutils.annotations.HTTP;
    2121import org.openstreetmap.josm.tools.Logging;
    2222
    23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    24 
    25 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     23import com.github.tomakehurst.wiremock.WireMockServer;
    2624
    2725/**
    2826 * Unit tests of {@link ApiUrlTestTask} class.
    2927 */
    30 public class ApiUrlTestTaskTest {
    31 
    32     /**
    33      * Setup tests
    34      */
    35     @Rule
    36     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    37     public JOSMTestRules test = new JOSMTestRules().preferences().timeout(30000);
    38 
     28@Timeout(30)
     29@BasicPreferences
     30@BasicWiremock
     31@HTTP
     32class ApiUrlTestTaskTest {
    3933    /**
    4034     * HTTP mock.
    4135     */
    42     @Rule
    43     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     36    @BasicWiremock
     37    WireMockServer wireMockServer;
    4438
    4539    private static final Component PARENT = new JLabel();
     
    4842     * Unit test of {@link ApiUrlTestTask#ApiUrlTestTask} - null url.
    4943     */
    50     @Test(expected = IllegalArgumentException.class)
    51     public void testNullApiUrl() {
    52         new ApiUrlTestTask(PARENT, null);
     44    @Test
     45    void testNullApiUrl() {
     46        assertThrows(IllegalArgumentException.class, () -> new ApiUrlTestTask(PARENT, null));
    5347    }
    5448
     
    5751     */
    5852    @Test
    59     public void testNominalUrl() {
    60         ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/__files/api"));
     53    void testNominalUrl() {
     54        ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/__files/api"));
    6155        task.run();
    6256        assertTrue(task.isSuccess());
     
    6761     */
    6862    @Test
    69     public void testAlertInvalidUrl() {
     63    void testAlertInvalidUrl() {
    7064        Logging.clearLastErrorAndWarnings();
    7165        ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "malformed url");
     
    8074     */
    8175    @Test
    82     public void testUnknownHost() {
     76    void testUnknownHost() {
    8377        Logging.clearLastErrorAndWarnings();
    8478        ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "http://unknown");
     
    9387     */
    9488    @Test
    95     public void testAlertInvalidServerResult() {
     89    void testAlertInvalidServerResult() {
    9690        Logging.clearLastErrorAndWarnings();
    97         wireMockRule.stubFor(get(urlEqualTo("/does-not-exist/0.6/capabilities"))
     91        wireMockServer.stubFor(get(urlEqualTo("/does-not-exist/0.6/capabilities"))
    9892                .willReturn(aResponse().withStatus(404)));
    9993
    100         ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/does-not-exist"));
     94        ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/does-not-exist"));
    10195        task.run();
    10296        assertFalse(task.isSuccess());
     
    109103     */
    110104    @Test
    111     public void testAlertInvalidCapabilities() {
     105    void testAlertInvalidCapabilities() {
    112106        Logging.clearLastErrorAndWarnings();
    113         ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/__files/invalid_api"));
     107        ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/__files/invalid_api"));
    114108        task.run();
    115109        assertFalse(task.isSuccess());
    116110        assertThat(Logging.getLastErrorAndWarnings().toString(), containsString(
    117111                "The OSM API server at 'XXX' did not return a valid response.<br>It is likely that 'XXX' is not an OSM API server."
    118                         .replace("XXX", wireMockRule.url("/__files/invalid_api"))));
     112                        .replace("XXX", wireMockServer.url("/__files/invalid_api"))));
    119113    }
    120114}
  • trunk/test/unit/org/openstreetmap/josm/io/OsmServerHistoryReaderTest.java

    r17903 r18106  
    22package org.openstreetmap.josm.io;
    33
    4 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    5 import static org.junit.Assert.assertEquals;
     4import static org.junit.jupiter.api.Assertions.assertEquals;
    65
    7 import org.junit.Before;
    8 import org.junit.Rule;
    9 import org.junit.Test;
    10 import org.openstreetmap.josm.JOSMFixture;
    11 import org.openstreetmap.josm.TestUtils;
     6import java.time.Instant;
     7
     8import org.junit.jupiter.api.BeforeEach;
     9import org.junit.jupiter.api.Test;
    1210import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1311import org.openstreetmap.josm.data.osm.history.History;
     
    1513import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1614import org.openstreetmap.josm.spi.preferences.Config;
     15import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     16import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     17import org.openstreetmap.josm.testutils.annotations.HTTP;
    1718
    18 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    19 
    20 import java.time.Instant;
     19import com.github.tomakehurst.wiremock.WireMockServer;
    2120
    2221/**
    2322 * Unit tests of {@link OsmServerHistoryReader} class.
    2423 */
    25 public class OsmServerHistoryReaderTest {
    26 
     24@BasicPreferences
     25@BasicWiremock
     26@HTTP
     27class OsmServerHistoryReaderTest {
    2728    /**
    2829     * HTTP mock.
    2930     */
    30     @Rule
    31     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     31    @BasicWiremock
     32    WireMockServer wireMockServer;
    3233
    3334    /**
    3435     * Setup tests.
    3536     */
    36     @Before
    37     public void setUp() {
    38         JOSMFixture.createUnitTestFixture().init();
    39         Config.getPref().put("osm-server.url", wireMockRule.url("/__files/api"));
     37    @BeforeEach
     38    void setUp() {
     39        Config.getPref().put("osm-server.url", wireMockServer.url("/__files/api"));
    4040    }
    4141
     
    4545     */
    4646    @Test
    47     public void testNode() throws OsmTransferException {
     47    void testNode() throws OsmTransferException {
    4848        OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.NODE, 266187);
    4949        HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
     
    6060     */
    6161    @Test
    62     public void testWay() throws OsmTransferException {
     62    void testWay() throws OsmTransferException {
    6363        OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.WAY, 3058844);
    6464        HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
     
    8080     */
    8181    @Test
    82     public void testRelation() throws OsmTransferException {
     82    void testRelation() throws OsmTransferException {
    8383        OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.RELATION, 49);
    8484        HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
  • trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java

    r17988 r18106  
    55import static com.github.tomakehurst.wiremock.client.WireMock.get;
    66import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    8 import static org.junit.Assert.assertEquals;
    9 import static org.junit.Assert.assertNotNull;
    10 import static org.junit.Assert.assertNull;
    11 import static org.junit.Assert.assertTrue;
     7import static org.junit.jupiter.api.Assertions.assertEquals;
     8import static org.junit.jupiter.api.Assertions.assertNotNull;
     9import static org.junit.jupiter.api.Assertions.assertNull;
     10import static org.junit.jupiter.api.Assertions.assertTrue;
    1211
    1312import java.io.StringReader;
     
    1514import java.util.regex.Matcher;
    1615
    17 import org.junit.Before;
    18 import org.junit.Rule;
    19 import org.junit.Test;
    20 import org.openstreetmap.josm.TestUtils;
     16import org.junit.jupiter.api.BeforeEach;
     17import org.junit.jupiter.api.Test;
    2118import org.openstreetmap.josm.data.Bounds;
    2219import org.openstreetmap.josm.io.OverpassDownloadReader.OverpassOutputFormat;
    23 import org.openstreetmap.josm.testutils.JOSMTestRules;
     20import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     21import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     22import org.openstreetmap.josm.testutils.annotations.HTTP;
    2423import org.openstreetmap.josm.tools.SearchCompilerQueryWizard;
    2524import org.openstreetmap.josm.tools.Utils;
    2625import org.openstreetmap.josm.tools.date.DateUtils;
    2726
    28 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    29 
    30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     27import com.github.tomakehurst.wiremock.WireMockServer;
    3128
    3229/**
    3330 * Unit tests of {@link OverpassDownloadReader} class.
    3431 */
    35 public class OverpassDownloadReaderTest {
    36 
    37     /**
    38      * Base test environment is enough
    39      */
    40     @Rule
    41     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    42     public JOSMTestRules test = new JOSMTestRules().preferences();
    43 
     32@BasicWiremock
     33@BasicPreferences
     34@HTTP
     35class OverpassDownloadReaderTest {
    4436    /**
    4537     * HTTP mock.
    4638     */
    47     @Rule
    48     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     39    @BasicWiremock
     40    WireMockServer wireMockServer;
    4941
    5042    private static final String NOMINATIM_URL_PATH = "/search?format=xml&q=";
     
    5345     * Setup test.
    5446     */
    55     @Before
     47    @BeforeEach
    5648    public void setUp() {
    57         NameFinder.NOMINATIM_URL_PROP.put(wireMockRule.url(NOMINATIM_URL_PATH));
     49        NameFinder.NOMINATIM_URL_PROP.put(wireMockServer.url(NOMINATIM_URL_PATH));
    5850    }
    5951
     
    7062     */
    7163    @Test
    72     public void testBbox() {
     64    void testBbox() {
    7365        final String query = getExpandedQuery("amenity=drinking_water");
    7466        assertEquals("" +
     
    8274
    8375    private void stubNominatim(String query) {
    84         wireMockRule.stubFor(get(urlEqualTo(NOMINATIM_URL_PATH + query))
     76        wireMockServer.stubFor(get(urlEqualTo(NOMINATIM_URL_PATH + query))
    8577                .willReturn(aResponse()
    8678                    .withStatus(200)
     
    9385     */
    9486    @Test
    95     public void testDate() {
     87    void testDate() {
    9688        LocalDateTime from = LocalDateTime.of(2017, 7, 14, 2, 40);
    9789        assertEquals("2016-07-14T02:40:00Z", OverpassDownloadReader.date("1 year", from));
     
    119111     */
    120112    @Test
    121     public void testDateNewer() {
     113    void testDateNewer() {
    122114        String query = getExpandedQuery("type:node and newer:3minutes");
    123115        String statement = query.substring(query.indexOf("node(newer:\"") + 12, query.lastIndexOf("\");"));
     
    133125     */
    134126    @Test
    135     public void testGeocodeArea() {
     127    void testGeocodeArea() {
    136128        stubNominatim("London");
    137129        final String query = getExpandedQuery("amenity=drinking_water in London");
     
    150142     */
    151143    @Test
    152     public void testGeocodeUnknownArea() {
     144    void testGeocodeUnknownArea() {
    153145        stubNominatim("foo-bar-baz-does-not-exist");
    154146        final String query = OverpassDownloadReader.expandExtendedQueries("{{geocodeArea:foo-bar-baz-does-not-exist}}");
     
    160152     */
    161153    @Test
    162     public void testOutputFormatStatement() {
     154    void testOutputFormatStatement() {
    163155        for (OverpassOutputFormat oof : OverpassOutputFormat.values()) {
    164156            Matcher m = OverpassDownloadReader.OUTPUT_FORMAT_STATEMENT.matcher("[out:"+oof.getDirective()+"]");
     
    182174     */
    183175    @Test
    184     public void testFixQuery() {
     176    void testFixQuery() {
    185177        assertNull(OverpassDownloadReader.fixQuery(null));
    186178
     
    224216     */
    225217    @Test
    226     public void testSearchName() throws Exception {
     218    void testSearchName() throws Exception {
    227219        try (StringReader reader = new StringReader(NameFinderTest.SAMPLE)) {
    228220            assertEquals(1942586L,
  • trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java

    r16412 r18106  
    22package org.openstreetmap.josm.io.imagery;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertNull;
    6 import static org.junit.Assert.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertNull;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    77
    88import java.io.IOException;
     
    1111import java.util.List;
    1212
    13 import org.junit.Rule;
    14 import org.junit.Test;
     13import org.junit.jupiter.api.Test;
     14import org.junit.jupiter.api.extension.RegisterExtension;
    1515import org.openstreetmap.josm.TestUtils;
    1616import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    1717import org.openstreetmap.josm.testutils.JOSMTestRules;
     18import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    1819
     20import com.github.tomakehurst.wiremock.WireMockServer;
    1921import com.github.tomakehurst.wiremock.client.WireMock;
    20 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
    21 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    2222
    2323import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2626 * Unit tests of {@link WMSImagery} class.
    2727 */
    28 public class WMSImageryTest {
     28@BasicWiremock
     29class WMSImageryTest {
    2930
    3031    /**
    3132     * Setup test
    3233     */
    33     @Rule
     34    @RegisterExtension
    3435    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    35     public JOSMTestRules test = new JOSMTestRules().projection();
     36    JOSMTestRules test = new JOSMTestRules().projection();
    3637
    37     @Rule
    38     public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()
    39             .dynamicPort());
     38    @BasicWiremock
     39    WireMockServer tileServer;
     40
    4041    /**
    4142     * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class
    4243     */
    4344    @Test
    44     public void testWMSGetCapabilitiesException() {
     45    void testWMSGetCapabilitiesException() {
    4546        Exception cause = new Exception("test");
    4647        WMSGetCapabilitiesException exc = new WMSGetCapabilitiesException(cause, "bar");
     
    5859     */
    5960    @Test
    60     public void testTicket15730() throws IOException, WMSGetCapabilitiesException {
     61    void testTicket15730() throws IOException, WMSGetCapabilitiesException {
    6162        tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
    6263                Files.readAllBytes(Paths.get(TestUtils.getRegressionDataDir(15730), "capabilities.xml"))
     
    6970
    7071    @Test
    71     public void testNestedLayers() throws Exception {
     72    void testNestedLayers() throws Exception {
    7273        tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
    7374                Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml")))));
     
    8485     */
    8586    @Test
    86     public void testTicket16248() throws IOException, WMSGetCapabilitiesException {
     87    void testTicket16248() throws IOException, WMSGetCapabilitiesException {
    8788        byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml")));
    8889        tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));
     
    101102     */
    102103    @Test
    103     public void testTicket19193() throws IOException, WMSGetCapabilitiesException {
     104    void testTicket19193() throws IOException, WMSGetCapabilitiesException {
    104105        byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(19193, "capabilities.xml")));
    105106        tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));
     
    120121     */
    121122    @Test
    122     public void testTicket16333() throws IOException, WMSGetCapabilitiesException {
     123    void testTicket16333() throws IOException, WMSGetCapabilitiesException {
    123124        tileServer.stubFor(
    124125                WireMock.get(WireMock.anyUrl())
     
    129130        WMSImagery wms = new WMSImagery(tileServer.url("any"));
    130131        assertEquals("https://duinoord.xs4all.nl/geoserver/ows?SERVICE=WMS&", wms.buildRootUrl());
    131         assertEquals(null, wms.getLayers().get(0).getName());
     132        assertNull(wms.getLayers().get(0).getName());
    132133        assertEquals("", wms.getLayers().get(0).getTitle());
    133134
     
    137138
    138139    @Test
    139     public void testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException {
     140    void testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException {
    140141        tileServer.stubFor(
    141142                WireMock.get(WireMock.anyUrl())
     
    148149    }
    149150}
    150 
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/AnnotationUtils.java

    r18051 r18106  
    1717 * @since 18037
    1818 */
    19 final class AnnotationUtils {
     19public final class AnnotationUtils {
    2020    private AnnotationUtils() {
    2121        // Utils class
  • trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportSenderTest.java

    r17195 r18106  
    88import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
    99import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    10 import static com.github.tomakehurst.wiremock.client.WireMock.verify;
    11 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    12 import static org.junit.Assert.assertEquals;
    13 import static org.junit.Assert.assertFalse;
    14 import static org.junit.Assert.assertNotNull;
    15 import static org.junit.Assert.assertNull;
     10import static org.junit.jupiter.api.Assertions.assertEquals;
     11import static org.junit.jupiter.api.Assertions.assertFalse;
     12import static org.junit.jupiter.api.Assertions.assertNotNull;
     13import static org.junit.jupiter.api.Assertions.assertNull;
    1614
    1715import java.net.URI;
    1816import java.util.List;
    1917
    20 import org.junit.Before;
    21 import org.junit.Rule;
    22 import org.junit.Test;
    23 import org.openstreetmap.josm.JOSMFixture;
     18import org.junit.jupiter.api.Test;
    2419import org.openstreetmap.josm.actions.ShowStatusReportAction;
    2520import org.openstreetmap.josm.spi.preferences.Config;
     21import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     22import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     23import org.openstreetmap.josm.testutils.annotations.HTTP;
    2624import org.openstreetmap.josm.testutils.mockers.OpenBrowserMocker;
    2725
    28 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     26import com.github.tomakehurst.wiremock.WireMockServer;
    2927
    3028/**
    3129 * Unit tests of {@link BugReportSender} class.
    3230 */
    33 public class BugReportSenderTest {
    34 
     31@BasicPreferences
     32@BasicWiremock
     33@HTTP
     34class BugReportSenderTest {
    3535    /**
    36      * Setup tests.
     36     * HTTP mock
    3737     */
    38     @Before
    39     public void setUp() {
    40         JOSMFixture.createUnitTestFixture().init();
    41     }
    42 
    43     /**
    44      * HTTP mock.
    45      */
    46     @Rule
    47     public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
     38    @BasicWiremock
     39    WireMockServer wireMockServer;
    4840
    4941    /**
     
    5244     */
    5345    @Test
    54     public void testBugReportSender() throws InterruptedException {
    55         Config.getPref().put("josm.url", wireMockRule.baseUrl());
    56         wireMockRule.stubFor(post(urlEqualTo("/josmticket"))
     46    void testBugReportSender() throws InterruptedException {
     47        Config.getPref().put("josm.url", wireMockServer.baseUrl());
     48        wireMockServer.stubFor(post(urlEqualTo("/josmticket"))
    5749                .willReturn(aResponse()
    5850                        .withStatus(200)
     
    7466        assertFalse(sender.isAlive());
    7567        assertNull(sender.getErrorMessage(), sender.getErrorMessage());
    76         verify(exactly(1), postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata=")));
     68        wireMockServer.verify(exactly(1), postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata=")));
    7769
    7870        List<URI> calledURIs = OpenBrowserMocker.getCalledURIs();
    7971        assertEquals(1, calledURIs.size());
    80         assertEquals(wireMockRule.url("/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff"), calledURIs.get(0).toString());
     72        assertEquals(wireMockServer.url("/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff"), calledURIs.get(0).toString());
    8173    }
    8274}
Note: See TracChangeset for help on using the changeset viewer.