source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialogTest.java@ 17275

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

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 6.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs;
3
4import static org.junit.jupiter.api.Assertions.assertNotNull;
5import static org.openstreetmap.josm.TestUtils.assertEqualsNewline;
6
7import java.util.ArrayList;
8
9import javax.swing.JPanel;
10
11import org.junit.jupiter.api.AfterEach;
12import org.junit.jupiter.api.BeforeEach;
13import org.junit.jupiter.api.Test;
14import org.junit.jupiter.api.extension.RegisterExtension;
15import org.openstreetmap.josm.data.SystemOfMeasurement;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.osm.DataSet;
18import org.openstreetmap.josm.data.osm.Node;
19import org.openstreetmap.josm.data.osm.User;
20import org.openstreetmap.josm.data.osm.Way;
21import org.openstreetmap.josm.gui.MainApplication;
22import org.openstreetmap.josm.gui.layer.OsmDataLayer;
23import org.openstreetmap.josm.testutils.JOSMTestRules;
24
25import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
26
27/**
28 * Unit tests of {@link InspectPrimitiveDialog} class.
29 */
30class InspectPrimitiveDialogTest {
31
32 /**
33 * Setup tests
34 */
35 @RegisterExtension
36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
37 public JOSMTestRules test = new JOSMTestRules().main().projection().mapStyles();
38
39 /**
40 * Setup test
41 */
42 @BeforeEach
43 public void setUp() {
44 SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.put("METRIC");
45
46 }
47
48 /**
49 * Cleanup test
50 */
51 @AfterEach
52 public void tearDown() {
53 SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.put(null);
54 }
55
56 /**
57 * Unit test of {@link InspectPrimitiveDialog#genericMonospacePanel}.
58 */
59 @Test
60 void testGenericMonospacePanel() {
61 assertNotNull(InspectPrimitiveDialog.genericMonospacePanel(new JPanel(), ""));
62 }
63
64 /**
65 * Unit test of {@link InspectPrimitiveDialog#buildDataText}.
66 */
67 @Test
68 void testBuildDataText() {
69 DataSet ds = new DataSet();
70 assertEqualsNewline("", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.allPrimitives())));
71 final Way way = new Way();
72 way.addNode(new Node(new LatLon(47.2687921, 11.390525)));
73 way.addNode(new Node(new LatLon(47.2689194, 11.3907301)));
74 way.addNode(new Node(new LatLon(47.2684158, 11.3914047)));
75 way.addNode(new Node(new LatLon(47.2682898, 11.3912034)));
76 way.setOsmId(1, 1);
77 int id = 2;
78 for (Node node : way.getNodes()) {
79 node.setOsmId(id, id);
80 id++;
81 }
82 way.getNodes().forEach(ds::addPrimitive);
83 ds.addPrimitive(way);
84 way.addNode(way.firstNode()); // close way
85 assertEqualsNewline(
86 "Way: 1\n" +
87 " Data Set: "+Integer.toHexString(ds.hashCode())+"\n" +
88 " Edited at: <new object>\n" +
89 " Edited by: <new object>\n" +
90 " Version: 1\n" +
91 " In changeset: 0\n" +
92 " Bounding box: 47.2682898, 11.3914047, 47.2689194, 11.390525\n" +
93 " Bounding box (projected): 5985976.274977, 1268085.3706241, 5986079.5621105, 1267987.4428681\n" +
94 " Center of bounding box: 47.2686046, 11.3909648\n" +
95 " Centroid: 47.2686049, 11.3909649\n" +
96 " Length: 193.3 m\n" +
97 " 5 Nodes: \n" +
98 " 2\n" +
99 " 3\n" +
100 " 4\n" +
101 " 5\n" +
102 " 2\n" +
103 "\n", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.getWays())));
104 }
105
106 /**
107 * Unit test of {@link InspectPrimitiveDialog#buildListOfEditorsText}.
108 */
109 @Test
110 void testBuildListOfEditorsText() {
111 DataSet ds = new DataSet();
112 assertEqualsNewline("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
113 ds.addPrimitive(new Node(LatLon.ZERO));
114 assertEqualsNewline("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
115 Node n = new Node(LatLon.ZERO);
116 n.setUser(User.getAnonymous());
117 ds.addPrimitive(n);
118 n = new Node(LatLon.ZERO);
119 n.setUser(User.getAnonymous());
120 ds.addPrimitive(n);
121 assertEqualsNewline(
122 "1 user last edited the selection:\n" +
123 "\n" +
124 " 2 <anonymous>\n",
125 InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
126 }
127
128 /**
129 * Unit test of {@link InspectPrimitiveDialog#buildMapPaintText}.
130 */
131 @Test
132 void testBuildMapPaintText() {
133 DataSet ds = new DataSet();
134 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
135
136 // CHECKSTYLE.OFF: LineLength
137 String baseText =
138 "Styles for \"node\":\n" +
139 "==================\n" +
140 "MapCSS style \"JOSM default (MapCSS)\"\n" +
141 "------------------------------------\n" +
142 "Display range: |z119.4329-Infinity\n" +
143 "Layer default\n" +
144 " * Cascade{ font-size:8.0; major-z-index:4.95; symbol-fill-color:#FF0000; symbol-shape:Keyword{square}; symbol-size:6.0; symbol-stroke-color:#FF0000; }\n" +
145 "\n" +
146 "List of generated Styles:\n" +
147 "-------------------------\n" +
148 " * NodeElement{z_idx=[4.95/0.0/0.0] symbol=[symbolShape=SQUARE size=6 stroke=java.awt.BasicStroke strokeColor=java.awt.Color[r=255,g=0,b=0] fillColor=java.awt.Color[r=255,g=0,b=0]]}\n" +
149 "\n" +
150 "\n";
151 // CHECKSTYLE.ON: LineLength
152
153 try {
154 MainApplication.getLayerManager().addLayer(layer);
155 assertEqualsNewline("", InspectPrimitiveDialog.buildMapPaintText());
156 Node n = new Node(LatLon.ZERO);
157 n.setUser(User.getAnonymous());
158 ds.addPrimitive(n);
159 ds.addSelected(n);
160 String text = InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", "");
161 assertEqualsNewline(baseText, text);
162 n = new Node(LatLon.ZERO);
163 n.setUser(User.getAnonymous());
164 ds.addPrimitive(n);
165 ds.addSelected(n);
166 assertEqualsNewline(baseText + baseText + "The 2 selected objects have identical style caches.\n",
167 InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", ""));
168 } finally {
169 MainApplication.getLayerManager().removeLayer(layer);
170 }
171 }
172}
Note: See TracBrowser for help on using the repository browser.