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

Last change on this file since 18870 was 18870, checked in by taylor.smock, 11 months ago

See #16567: Update to JUnit 5

This converts most tests to use @Annotations. There are also some performance
improvements as it relates to tests.

  • 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.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotNull;
6import static org.junit.jupiter.api.Assertions.assertNull;
7import static org.junit.jupiter.api.Assertions.assertTrue;
8
9import java.util.Collections;
10
11import org.junit.jupiter.api.BeforeEach;
12import org.junit.jupiter.api.Test;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.gpx.GpxConstants;
15import org.openstreetmap.josm.data.gpx.GpxData;
16import org.openstreetmap.josm.data.gpx.GpxLink;
17import org.openstreetmap.josm.data.gpx.WayPoint;
18import org.openstreetmap.josm.data.osm.DataSet;
19import org.openstreetmap.josm.gui.MainApplication;
20import org.openstreetmap.josm.gui.MapFrame;
21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
22import org.openstreetmap.josm.spi.preferences.Config;
23import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
24import org.openstreetmap.josm.testutils.annotations.Main;
25import org.openstreetmap.josm.testutils.annotations.Projection;
26
27/**
28 * Unit tests of {@link MarkerLayer} class.
29 */
30@BasicPreferences
31@Main
32@Projection
33class 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}
Note: See TracBrowser for help on using the repository browser.