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

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

unit test robustness

  • Property svn:eol-style set to native
File size: 3.1 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
18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
20/**
21 * Unit tests for class {@link AddImageryLayerAction}.
22 */
23public final class AddImageryLayerActionTest {
24 /**
25 * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
26 */
27 @Rule
28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
29 public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI().timeout(15000);
30
31 /**
32 * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
33 */
34 @Test
35 public void testEnabledState() {
36 assertFalse(new AddImageryLayerAction(new ImageryInfo()).isEnabled());
37 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
38 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
39 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
40 assertFalse(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
41 }
42
43 /**
44 * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases.
45 */
46 @Test
47 public void testActionPerformedEnabled() {
48 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
49 new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
50 List<TMSLayer> tmsLayers = Main.getLayerManager().getLayersOfType(TMSLayer.class);
51 assertEquals(1, tmsLayers.size());
52
53 try {
54 new AddImageryLayerAction(new ImageryInfo("wms.openstreetmap.fr", "http://wms.openstreetmap.fr/wms?",
55 "wms_endpoint", null, null)).actionPerformed(null);
56 List<WMSLayer> wmsLayers = Main.getLayerManager().getLayersOfType(WMSLayer.class);
57 assertEquals(1, wmsLayers.size());
58
59 Main.getLayerManager().removeLayer(wmsLayers.get(0));
60 } finally {
61 Main.getLayerManager().removeLayer(tmsLayers.get(0));
62 }
63 }
64
65 /**
66 * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
67 */
68 @Test
69 public void testActionPerformedDisabled() {
70 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
71 new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
72 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
73 }
74}
Note: See TracBrowser for help on using the repository browser.