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.net.MalformedURLException;
|
---|
10 | import java.net.URI;
|
---|
11 | import java.util.Collections;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.BeforeEach;
|
---|
14 | import org.junit.jupiter.api.Test;
|
---|
15 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
16 | import org.openstreetmap.josm.data.gpx.GpxConstants;
|
---|
17 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
18 | import org.openstreetmap.josm.data.gpx.GpxLink;
|
---|
19 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
20 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
21 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
22 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
23 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
24 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
25 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
26 | import org.openstreetmap.josm.testutils.annotations.I18n;
|
---|
27 | import org.openstreetmap.josm.testutils.annotations.Main;
|
---|
28 | import org.openstreetmap.josm.testutils.annotations.Projection;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Unit tests of {@link MarkerLayer} class.
|
---|
32 | */
|
---|
33 | @BasicPreferences
|
---|
34 | @Main
|
---|
35 | @Projection
|
---|
36 | @I18n
|
---|
37 | class MarkerLayerTest {
|
---|
38 | /**
|
---|
39 | * Setup tests
|
---|
40 | */
|
---|
41 | @BeforeEach
|
---|
42 | public void setUp() {
|
---|
43 | Config.getPref().putBoolean("marker.traceaudio", true);
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test of {@link MarkerLayer#MarkerLayer}.
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | void testMarkerLayer() {
|
---|
51 | MarkerLayer layer = new MarkerLayer(new GpxData(), "foo", null, null);
|
---|
52 | MainApplication.getLayerManager().addLayer(layer);
|
---|
53 |
|
---|
54 | assertEquals("foo", layer.getName());
|
---|
55 | assertNull(layer.getColor());
|
---|
56 | assertNotNull(layer.getIcon());
|
---|
57 | assertEquals("0 markers", layer.getToolTipText());
|
---|
58 | assertEquals("<html>foo consists of 0 markers</html>", layer.getInfoComponent());
|
---|
59 | assertTrue(layer.getMenuEntries().length > 10);
|
---|
60 |
|
---|
61 | GpxData gpx = new GpxData();
|
---|
62 | WayPoint wpt = new WayPoint(LatLon.ZERO);
|
---|
63 | wpt.attr.put(GpxConstants.META_LINKS, Collections.singletonList(new GpxLink("https://josm.openstreetmap.de")));
|
---|
64 | wpt.getExtensions().add("josm", "offset", "1.0");
|
---|
65 | gpx.waypoints.add(wpt);
|
---|
66 | wpt = new WayPoint(LatLon.ZERO);
|
---|
67 | wpt.getExtensions().add("josm", "offset", "NaN");
|
---|
68 | gpx.waypoints.add(wpt);
|
---|
69 | layer = new MarkerLayer(gpx, "bar", null, null);
|
---|
70 |
|
---|
71 | assertEquals("bar", layer.getName());
|
---|
72 | assertNull(layer.getColor());
|
---|
73 | assertNotNull(layer.getIcon());
|
---|
74 | assertEquals("3 markers", layer.getToolTipText());
|
---|
75 | assertEquals("<html>bar consists of 3 markers</html>", layer.getInfoComponent());
|
---|
76 | assertTrue(layer.getMenuEntries().length > 10);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Unit test of {@code Main.map.mapView.playHeadMarker}.
|
---|
81 | */
|
---|
82 | @Test
|
---|
83 | void testPlayHeadMarker() {
|
---|
84 | try {
|
---|
85 | MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "", null));
|
---|
86 | MapFrame map = MainApplication.getMap();
|
---|
87 | MarkerLayer layer = new MarkerLayer(new GpxData(), null, null, null);
|
---|
88 | assertNull(map.mapView.playHeadMarker);
|
---|
89 | MainApplication.getLayerManager().addLayer(layer);
|
---|
90 | assertNotNull(map.mapView.playHeadMarker);
|
---|
91 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
92 | } finally {
|
---|
93 | if (MainApplication.isDisplayingMapView()) {
|
---|
94 | MainApplication.getMap().mapView.playHeadMarker = null;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Ensure that if a file is unable to be read, we return an empty list instead of a list with {@code null} in it.
|
---|
101 | */
|
---|
102 | @Test
|
---|
103 | void testNonRegression23316() throws MalformedURLException {
|
---|
104 | MarkerLayer layer = new MarkerLayer(new GpxData(), null, null, null);
|
---|
105 | layer.setCurrentMarker(new ImageMarker(LatLon.ZERO, URI.create("file:/not_a_real_file_123456789.jpg").toURL(),
|
---|
106 | layer, 0, 0));
|
---|
107 | assertEquals(Collections.emptyList(), layer.getSelection());
|
---|
108 | }
|
---|
109 | }
|
---|