source: josm/trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java@ 10378

Last change on this file since 10378 was 10373, checked in by Don-vip, 8 years ago

fix #12949 - Use test rule instead of JOSMFixture to speed up tests (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import java.util.List;
9
10import org.junit.Rule;
11import org.junit.Test;
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.imagery.ImageryInfo;
14import org.openstreetmap.josm.gui.layer.TMSLayer;
15import org.openstreetmap.josm.gui.layer.WMSLayer;
16import org.openstreetmap.josm.testutils.JOSMTestRules;
17
18/**
19 * Unit tests for class {@link AddImageryLayerAction}.
20 */
21public final class AddImageryLayerActionTest {
22 /**
23 * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
24 */
25 @Rule
26 public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI();
27
28 /**
29 * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
30 */
31 @Test
32 public void testEnabledState() {
33 assertFalse(new AddImageryLayerAction(new ImageryInfo()).isEnabled());
34 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
35 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
36 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
37 assertFalse(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
38 }
39
40 /**
41 * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases.
42 */
43 @Test
44 public void testActionPerformedEnabled() {
45 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
46 new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
47 List<TMSLayer> tmsLayers = Main.getLayerManager().getLayersOfType(TMSLayer.class);
48 assertEquals(1, tmsLayers.size());
49
50 try {
51 new AddImageryLayerAction(new ImageryInfo("wms.openstreetmap.fr", "http://wms.openstreetmap.fr/wms?",
52 "wms_endpoint", null, null)).actionPerformed(null);
53 List<WMSLayer> wmsLayers = Main.getLayerManager().getLayersOfType(WMSLayer.class);
54 assertEquals(1, wmsLayers.size());
55
56 Main.map.mapView.removeLayer(wmsLayers.get(0));
57 } finally {
58 Main.map.mapView.removeLayer(tmsLayers.get(0));
59 }
60 }
61
62 /**
63 * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
64 */
65 @Test
66 public void testActionPerformedDisabled() {
67 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
68 new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
69 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
70 }
71}
Note: See TracBrowser for help on using the repository browser.