source: josm/trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java@ 15496

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

fix #16796 - Rework of GPX track colors / layer preferences (patch by Bjoeni)

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.markerlayer;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8
9import java.util.Arrays;
10
11import org.junit.Before;
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.data.gpx.GpxConstants;
16import org.openstreetmap.josm.data.gpx.GpxData;
17import org.openstreetmap.josm.data.gpx.GpxLink;
18import org.openstreetmap.josm.data.gpx.WayPoint;
19import org.openstreetmap.josm.data.osm.DataSet;
20import org.openstreetmap.josm.gui.MainApplication;
21import org.openstreetmap.josm.gui.MapFrame;
22import org.openstreetmap.josm.gui.layer.OsmDataLayer;
23import org.openstreetmap.josm.spi.preferences.Config;
24import org.openstreetmap.josm.testutils.JOSMTestRules;
25
26import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27
28/**
29 * Unit tests of {@link MarkerLayer} class.
30 */
31public 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}
Note: See TracBrowser for help on using the repository browser.