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