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

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

see #12313 - fix unit tests properly

  • Property svn:eol-style set to native
File size: 3.4 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.assertTrue;
6
7import java.util.List;
8
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.imagery.ImageryInfo;
13import org.openstreetmap.josm.gui.layer.TMSLayer;
14import org.openstreetmap.josm.gui.layer.WMSLayer;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19/**
20 * Unit tests for class {@link AddImageryLayerAction}.
21 */
22public final class AddImageryLayerActionTest {
23 /**
24 * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
25 * The timeout is set to default httpclient read timeout + connect timeout + a small delay to ignore
26 * common but harmless network issues.
27 */
28 @Rule
29 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
30 public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI().timeout(45500);
31
32 /**
33 * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
34 */
35 @Test
36 public void testEnabledState() {
37 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo")).isEnabled());
38 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
39 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
40 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
41 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
42 }
43
44 /**
45 * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases.
46 */
47 @Test
48 public void testActionPerformedEnabled() {
49 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
50 new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
51 List<TMSLayer> tmsLayers = Main.getLayerManager().getLayersOfType(TMSLayer.class);
52 assertEquals(1, tmsLayers.size());
53
54 try {
55 new AddImageryLayerAction(new ImageryInfo("wms.openstreetmap.fr", "http://wms.openstreetmap.fr/wms?",
56 "wms_endpoint", null, null)).actionPerformed(null);
57 List<WMSLayer> wmsLayers = Main.getLayerManager().getLayersOfType(WMSLayer.class);
58 assertEquals(1, wmsLayers.size());
59
60 Main.getLayerManager().removeLayer(wmsLayers.get(0));
61 } finally {
62 Main.getLayerManager().removeLayer(tmsLayers.get(0));
63 }
64 }
65
66 /**
67 * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
68 */
69 @Test
70 public void testActionPerformedDisabled() {
71 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
72 try {
73 new AddImageryLayerAction(new ImageryInfo("foo")).actionPerformed(null);
74 } catch (IllegalArgumentException expected) {
75 assertEquals("Parameter 'info.url' must not be null", expected.getMessage());
76 }
77 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
78 }
79}
Note: See TracBrowser for help on using the repository browser.