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

Last change on this file since 16159 was 16159, checked in by simon04, 4 years ago

see #18948 - Use Collections.singletonMap instead of ImmutableMap.of

  • 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.Assert.assertEquals;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertNull;
8import static org.junit.Assert.assertTrue;
9
10import java.util.Collections;
11
12import org.awaitility.Awaitility;
13import org.junit.Rule;
14import org.junit.Test;
15import org.openstreetmap.josm.actions.MergeLayerActionTest.MergeLayerExtendedDialogMocker;
16import org.openstreetmap.josm.data.gpx.GpxData;
17import org.openstreetmap.josm.gui.MainApplication;
18import org.openstreetmap.josm.gui.layer.GpxLayerTest;
19import org.openstreetmap.josm.gui.layer.TMSLayer;
20import org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction.PrecacheWmsTask;
21import org.openstreetmap.josm.TestUtils;
22import org.openstreetmap.josm.testutils.JOSMTestRules;
23import org.openstreetmap.josm.testutils.TileSourceRule;
24import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
25
26import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27
28/**
29 * Unit tests of {@link DownloadWmsAlongTrackAction} class.
30 */
31public class DownloadWmsAlongTrackActionTest {
32
33 /**
34 * Setup test.
35 */
36 @Rule
37 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
38 public JOSMTestRules test = new JOSMTestRules().main().projection().fakeImagery().timeout(20000);
39
40 /**
41 * Test action without layer.
42 */
43 @Test
44 public void testNoLayer() {
45 TestUtils.assumeWorkingJMockit();
46 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(
47 Collections.singletonMap("There are no imagery layers.", 0)
48 );
49
50 assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
51
52 assertEquals(1, jopsMocker.getInvocationLog().size());
53 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
54 assertEquals(0, (int) invocationLogEntry[0]);
55 assertEquals("No imagery layers", invocationLogEntry[2]);
56 }
57
58 /**
59 * Test action with a TMS layer.
60 * @throws Exception if an error occurs
61 */
62 @Test
63 public void testTMSLayer() throws Exception {
64 TestUtils.assumeWorkingJMockit();
65 final MergeLayerExtendedDialogMocker edMocker = new MergeLayerExtendedDialogMocker();
66 edMocker.getMockResultMap().put("Please select the imagery layer.", "Download");
67
68 final TileSourceRule tileSourceRule = this.test.getTileSourceRule();
69
70 final TMSLayer layer = new TMSLayer(
71 tileSourceRule.getSourcesList().get(0).getImageryInfo(tileSourceRule.port())
72 );
73 try {
74 MainApplication.getLayerManager().addLayer(layer);
75 TMSLayer.getCache().clear();
76 assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
77 // Perform action
78 PrecacheWmsTask task = new DownloadWmsAlongTrackAction(GpxLayerTest.getMinimalGpxData()).createTask();
79 assertNotNull(task);
80 task.run();
81 // Ensure cache is (eventually) not empty
82 Awaitility.await().atMost(10000, MILLISECONDS).until(() -> !TMSLayer.getCache().getMatching(".*").isEmpty());
83 } finally {
84 // Ensure we clean the place before leaving, even if test fails.
85 MainApplication.getLayerManager().removeLayer(layer);
86 }
87
88 assertEquals(1, edMocker.getInvocationLog().size());
89 Object[] invocationLogEntry = edMocker.getInvocationLog().get(0);
90 assertEquals(1, (int) invocationLogEntry[0]);
91 assertEquals("Select imagery layer", invocationLogEntry[2]);
92 }
93}
Note: See TracBrowser for help on using the repository browser.