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

Last change on this file was 18958, checked in by taylor.smock, 3 months ago

Fix #23418: Improve unit test consistency when run with non-English locales

This also fixes some tests that fail when run individually.

  • Property svn:eol-style set to native
File size: 4.1 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.net.MalformedURLException;
10import java.net.URI;
11import java.util.Collections;
12
13import org.junit.jupiter.api.BeforeEach;
14import org.junit.jupiter.api.Test;
15import org.openstreetmap.josm.data.coor.LatLon;
16import org.openstreetmap.josm.data.gpx.GpxConstants;
17import org.openstreetmap.josm.data.gpx.GpxData;
18import org.openstreetmap.josm.data.gpx.GpxLink;
19import org.openstreetmap.josm.data.gpx.WayPoint;
20import org.openstreetmap.josm.data.osm.DataSet;
21import org.openstreetmap.josm.gui.MainApplication;
22import org.openstreetmap.josm.gui.MapFrame;
23import org.openstreetmap.josm.gui.layer.OsmDataLayer;
24import org.openstreetmap.josm.spi.preferences.Config;
25import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
26import org.openstreetmap.josm.testutils.annotations.I18n;
27import org.openstreetmap.josm.testutils.annotations.Main;
28import org.openstreetmap.josm.testutils.annotations.Projection;
29
30/**
31 * Unit tests of {@link MarkerLayer} class.
32 */
33@BasicPreferences
34@Main
35@Projection
36@I18n
37class 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}
Note: See TracBrowser for help on using the repository browser.