| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.Assert.assertEquals;
|
|---|
| 5 | import static org.junit.Assert.assertFalse;
|
|---|
| 6 | import static org.junit.Assert.assertTrue;
|
|---|
| 7 |
|
|---|
| 8 | import java.util.List;
|
|---|
| 9 |
|
|---|
| 10 | import org.junit.BeforeClass;
|
|---|
| 11 | import org.junit.Test;
|
|---|
| 12 | import org.openstreetmap.josm.JOSMFixture;
|
|---|
| 13 | import org.openstreetmap.josm.Main;
|
|---|
| 14 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
|---|
| 15 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
|---|
| 16 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Unit tests for class {@link AddImageryLayerAction}.
|
|---|
| 20 | */
|
|---|
| 21 | public final class AddImageryLayerActionTest {
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Setup test.
|
|---|
| 25 | */
|
|---|
| 26 | @BeforeClass
|
|---|
| 27 | public static void setUp() {
|
|---|
| 28 | JOSMFixture.createUnitTestFixture().init(true);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
|
|---|
| 33 | */
|
|---|
| 34 | @Test
|
|---|
| 35 | public void testEnabledState() {
|
|---|
| 36 | assertFalse(new AddImageryLayerAction(new ImageryInfo()).isEnabled());
|
|---|
| 37 | assertFalse(new AddImageryLayerAction(new ImageryInfo("google", "http://maps.google.com/api", "tms", null, null)).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 | assertFalse(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.map.mapView.getLayersOfType(TMSLayer.class).isEmpty());
|
|---|
| 50 | new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
|
|---|
| 51 | List<TMSLayer> tmsLayers = Main.map.mapView.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.map.mapView.getLayersOfType(WMSLayer.class);
|
|---|
| 58 | assertEquals(1, wmsLayers.size());
|
|---|
| 59 |
|
|---|
| 60 | Main.map.mapView.removeLayer(wmsLayers.get(0));
|
|---|
| 61 | } finally {
|
|---|
| 62 | Main.map.mapView.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.map.mapView.getLayersOfType(TMSLayer.class).isEmpty());
|
|---|
| 72 | new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
|
|---|
| 73 | assertTrue(Main.map.mapView.getLayersOfType(TMSLayer.class).isEmpty());
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|