1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.markerlayer;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertNull;
|
---|
7 | import static org.junit.Assert.assertTrue;
|
---|
8 |
|
---|
9 | import java.util.Arrays;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Rule;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
15 | import org.openstreetmap.josm.data.gpx.GpxConstants;
|
---|
16 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
17 | import org.openstreetmap.josm.data.gpx.GpxLink;
|
---|
18 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
19 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
20 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
21 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
22 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
23 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
24 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
25 |
|
---|
26 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Unit tests of {@link MarkerLayer} class.
|
---|
30 | */
|
---|
31 | public class MarkerLayerTest {
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * For creating layers
|
---|
35 | */
|
---|
36 | @Rule
|
---|
37 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
38 | public JOSMTestRules test = new JOSMTestRules().main().preferences().projection();
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Setup tests
|
---|
42 | */
|
---|
43 | @Before
|
---|
44 | public void setUp() {
|
---|
45 | Config.getPref().putBoolean("marker.traceaudio", true);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Unit test of {@link MarkerLayer#MarkerLayer}.
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | public void testMarkerLayer() {
|
---|
53 | MarkerLayer layer = new MarkerLayer(new GpxData(), "foo", null, null);
|
---|
54 | MainApplication.getLayerManager().addLayer(layer);
|
---|
55 |
|
---|
56 | assertEquals("foo", layer.getName());
|
---|
57 | assertNull(layer.getColor());
|
---|
58 | assertNotNull(layer.getIcon());
|
---|
59 | assertEquals("0 markers", layer.getToolTipText());
|
---|
60 | assertEquals("<html>foo consists of 0 markers</html>", layer.getInfoComponent());
|
---|
61 | assertTrue(layer.getMenuEntries().length > 10);
|
---|
62 |
|
---|
63 | GpxData gpx = new GpxData();
|
---|
64 | WayPoint wpt = new WayPoint(LatLon.ZERO);
|
---|
65 | wpt.attr.put(GpxConstants.META_LINKS, Arrays.asList(new GpxLink("https://josm.openstreetmap.de")));
|
---|
66 | wpt.getExtensions().add("josm", "offset", "1.0");
|
---|
67 | gpx.waypoints.add(wpt);
|
---|
68 | wpt = new WayPoint(LatLon.ZERO);
|
---|
69 | wpt.getExtensions().add("josm", "offset", "NaN");
|
---|
70 | gpx.waypoints.add(wpt);
|
---|
71 | layer = new MarkerLayer(gpx, "bar", null, null);
|
---|
72 |
|
---|
73 | assertEquals("bar", layer.getName());
|
---|
74 | assertNull(layer.getColor());
|
---|
75 | assertNotNull(layer.getIcon());
|
---|
76 | assertEquals("3 markers", layer.getToolTipText());
|
---|
77 | assertEquals("<html>bar consists of 3 markers</html>", layer.getInfoComponent());
|
---|
78 | assertTrue(layer.getMenuEntries().length > 10);
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Unit test of {@code Main.map.mapView.playHeadMarker}.
|
---|
83 | */
|
---|
84 | @Test
|
---|
85 | public void testPlayHeadMarker() {
|
---|
86 | try {
|
---|
87 | MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "", null));
|
---|
88 | MapFrame map = MainApplication.getMap();
|
---|
89 | MarkerLayer layer = new MarkerLayer(new GpxData(), null, null, null);
|
---|
90 | assertNull(map.mapView.playHeadMarker);
|
---|
91 | MainApplication.getLayerManager().addLayer(layer);
|
---|
92 | assertNotNull(map.mapView.playHeadMarker);
|
---|
93 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
94 | } finally {
|
---|
95 | if (MainApplication.isDisplayingMapView()) {
|
---|
96 | MainApplication.getMap().mapView.playHeadMarker = null;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|