source: josm/trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackActionTest.java

Last change on this file was 18893, checked in by taylor.smock, 6 months ago

Fix #16567: Upgrade to JUnit 5

JOSMTestRules and JOSMTestFixture can reset the default JOSM profile, which can
be unexpected for new contributors. This updates all tests to use JUnit 5 and
the new JUnit 5 annotations.

This also renames MapCSSStyleSourceFilterTest to MapCSSStyleSourceFilterPerformanceTest
to match the naming convention for performance tests and fixes some lint issues.

This was tested by running all tests individually and together.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.gpx;
3
4import static java.util.concurrent.TimeUnit.MILLISECONDS;
5import static org.junit.jupiter.api.Assertions.assertEquals;
6import static org.junit.jupiter.api.Assertions.assertNotNull;
7import static org.junit.jupiter.api.Assertions.assertNull;
8import static org.junit.jupiter.api.Assertions.assertTrue;
9
10import java.util.Collections;
11
12import org.awaitility.Awaitility;
13import org.junit.jupiter.api.Test;
14import org.junit.jupiter.api.Timeout;
15import org.openstreetmap.josm.TestUtils;
16import org.openstreetmap.josm.actions.MergeLayerActionTest.MergeLayerExtendedDialogMocker;
17import org.openstreetmap.josm.data.gpx.GpxData;
18import org.openstreetmap.josm.gui.MainApplication;
19import org.openstreetmap.josm.gui.layer.GpxLayerTest;
20import org.openstreetmap.josm.gui.layer.TMSLayer;
21import org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction.PrecacheWmsTask;
22import org.openstreetmap.josm.testutils.annotations.FakeImagery;
23import org.openstreetmap.josm.testutils.annotations.Main;
24import org.openstreetmap.josm.testutils.annotations.Projection;
25import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
26
27/**
28 * Unit tests of {@link DownloadWmsAlongTrackAction} class.
29 */
30@FakeImagery
31@Main
32@Projection
33@Timeout(20)
34class DownloadWmsAlongTrackActionTest {
35
36 /**
37 * Test action without layer.
38 */
39 @Test
40 void testNoLayer() {
41 TestUtils.assumeWorkingJMockit();
42 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(
43 Collections.singletonMap("There are no imagery layers.", 0)
44 );
45
46 assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
47
48 assertEquals(1, jopsMocker.getInvocationLog().size());
49 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
50 assertEquals(0, (int) invocationLogEntry[0]);
51 assertEquals("No imagery layers", invocationLogEntry[2]);
52 }
53
54 /**
55 * Test action with a TMS layer.
56 * @throws Exception if an error occurs
57 */
58 @Test
59 void testTMSLayer(FakeImagery.FakeImageryWireMockExtension fakeImageryWireMockExtension) throws Exception {
60 TestUtils.assumeWorkingJMockit();
61 final MergeLayerExtendedDialogMocker edMocker = new MergeLayerExtendedDialogMocker();
62 edMocker.getMockResultMap().put("Please select the imagery layer.", "Download");
63
64 final TMSLayer layer = new TMSLayer(
65 fakeImageryWireMockExtension.getSourcesList().get(0).getImageryInfo(fakeImageryWireMockExtension.getRuntimeInfo().getHttpPort())
66 );
67 try {
68 MainApplication.getLayerManager().addLayer(layer);
69 TMSLayer.getCache().clear();
70 assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
71 // Perform action
72 PrecacheWmsTask task = new DownloadWmsAlongTrackAction(GpxLayerTest.getMinimalGpxData()).createTask();
73 assertNotNull(task);
74 task.run();
75 // Ensure cache is (eventually) not empty
76 Awaitility.await().atMost(10000, MILLISECONDS).until(() -> !TMSLayer.getCache().getMatching(".*").isEmpty());
77 } finally {
78 // Ensure we clean the place before leaving, even if test fails.
79 MainApplication.getLayerManager().removeLayer(layer);
80 }
81
82 assertEquals(1, edMocker.getInvocationLog().size());
83 Object[] invocationLogEntry = edMocker.getInvocationLog().get(0);
84 assertEquals(1, (int) invocationLogEntry[0]);
85 assertEquals("Select imagery layer", invocationLogEntry[2]);
86 }
87}
Note: See TracBrowser for help on using the repository browser.