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

Last change on this file since 12632 was 12632, checked in by Don-vip, 7 years ago

see #15182 - fix unit tests

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.gpx;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.gpx.GpxData;
13import org.openstreetmap.josm.data.imagery.ImageryInfo;
14import org.openstreetmap.josm.gui.layer.GpxLayerTest;
15import org.openstreetmap.josm.gui.layer.TMSLayer;
16import org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction.PrecacheWmsTask;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20
21/**
22 * Unit tests of {@link DownloadWmsAlongTrackAction} class.
23 */
24public class DownloadWmsAlongTrackActionTest {
25
26 /**
27 * Setup test.
28 */
29 @Rule
30 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
31 public JOSMTestRules test = new JOSMTestRules().platform().main().projection();
32
33 /**
34 * Test action without layer.
35 */
36 @Test
37 public void testNoLayer() {
38 assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
39 }
40
41 /**
42 * Test action with a TMS layer.
43 * @throws Exception if an error occurs
44 */
45 @Test
46 public void testTMSLayer() throws Exception {
47 // Create new TMS layer and clear cache
48 TMSLayer layer = new TMSLayer(new ImageryInfo("OSM TMS", "https://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png", "tms", null, null));
49 try {
50 Main.getLayerManager().addLayer(layer);
51 TMSLayer.getCache().clear();
52 assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
53 // Perform action
54 PrecacheWmsTask task = new DownloadWmsAlongTrackAction(GpxLayerTest.getMinimalGpxData()).createTask();
55 assertNotNull(task);
56 task.run();
57 // Ensure cache is not empty
58 assertFalse(TMSLayer.getCache().getMatching(".*").isEmpty());
59 } finally {
60 // Ensure we clean the place before leaving, even if test fails.
61 Main.getLayerManager().removeLayer(layer);
62 }
63 }
64}
Note: See TracBrowser for help on using the repository browser.