1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 |
|
---|
7 | import java.util.ArrayList;
|
---|
8 |
|
---|
9 | import javax.swing.JPanel;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.User;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
19 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
20 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Unit tests of {@link InspectPrimitiveDialog} class.
|
---|
26 | */
|
---|
27 | public class InspectPrimitiveDialogTest {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Setup tests
|
---|
31 | */
|
---|
32 | @Rule
|
---|
33 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
34 | public JOSMTestRules test = new JOSMTestRules().main().projection().mapStyles();
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Unit test of {@link InspectPrimitiveDialog#genericMonospacePanel}.
|
---|
38 | */
|
---|
39 | @Test
|
---|
40 | public void testGenericMonospacePanel() {
|
---|
41 | assertNotNull(InspectPrimitiveDialog.genericMonospacePanel(new JPanel(), ""));
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Unit test of {@link InspectPrimitiveDialog#buildDataText}.
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | public void testBuildDataText() {
|
---|
49 | DataSet ds = new DataSet();
|
---|
50 | assertEquals("", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.allPrimitives())));
|
---|
51 | final Way way = new Way();
|
---|
52 | way.addNode(new Node(new LatLon(47.2687921, 11.390525)));
|
---|
53 | way.addNode(new Node(new LatLon(47.2689194, 11.3907301)));
|
---|
54 | way.addNode(new Node(new LatLon(47.2684158, 11.3914047)));
|
---|
55 | way.addNode(new Node(new LatLon(47.2682898, 11.3912034)));
|
---|
56 | way.setOsmId(1, 1);
|
---|
57 | int id = 2;
|
---|
58 | for (Node node : way.getNodes()) {
|
---|
59 | node.setOsmId(id, id);
|
---|
60 | id++;
|
---|
61 | }
|
---|
62 | way.getNodes().forEach(ds::addPrimitive);
|
---|
63 | ds.addPrimitive(way);
|
---|
64 | way.addNode(way.firstNode()); // close way
|
---|
65 | assertEquals(
|
---|
66 | "Way: 1\n" +
|
---|
67 | " Data Set: "+Integer.toHexString(ds.hashCode())+"\n" +
|
---|
68 | " Edited at: <new object>\n" +
|
---|
69 | " Edited by: <new object>\n" +
|
---|
70 | " Version: 1\n" +
|
---|
71 | " In changeset: 0\n" +
|
---|
72 | " Bounding box: 47.2682898, 11.3914047, 47.2689194, 11.390525\n" +
|
---|
73 | " Bounding box (projected): 5985976.274977, 1268085.3706241, 5986079.5621105, 1267987.4428681\n" +
|
---|
74 | " Center of bounding box: 47.2686046, 11.3909648\n" +
|
---|
75 | " Centroid: 47.2686049, 11.3909649\n" +
|
---|
76 | " 5 Nodes: \n" +
|
---|
77 | " 2\n" +
|
---|
78 | " 3\n" +
|
---|
79 | " 4\n" +
|
---|
80 | " 5\n" +
|
---|
81 | " 2\n" +
|
---|
82 | "\n", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.getWays())));
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Unit test of {@link InspectPrimitiveDialog#buildListOfEditorsText}.
|
---|
87 | */
|
---|
88 | @Test
|
---|
89 | public void testBuildListOfEditorsText() {
|
---|
90 | DataSet ds = new DataSet();
|
---|
91 | assertEquals("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
92 | ds.addPrimitive(new Node(LatLon.ZERO));
|
---|
93 | assertEquals("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
94 | Node n = new Node(LatLon.ZERO);
|
---|
95 | n.setUser(User.getAnonymous());
|
---|
96 | ds.addPrimitive(n);
|
---|
97 | n = new Node(LatLon.ZERO);
|
---|
98 | n.setUser(User.getAnonymous());
|
---|
99 | ds.addPrimitive(n);
|
---|
100 | assertEquals(
|
---|
101 | "1 user last edited the selection:\n" +
|
---|
102 | "\n" +
|
---|
103 | " 2 <anonymous>\n",
|
---|
104 | InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Unit test of {@link InspectPrimitiveDialog#buildMapPaintText}.
|
---|
109 | */
|
---|
110 | @Test
|
---|
111 | public void testBuildMapPaintText() {
|
---|
112 | DataSet ds = new DataSet();
|
---|
113 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
114 |
|
---|
115 | // CHECKSTYLE.OFF: LineLength
|
---|
116 | String baseText =
|
---|
117 | "Styles for \"node\":\n" +
|
---|
118 | "==================\n" +
|
---|
119 | "MapCSS style \"JOSM default (MapCSS)\"\n" +
|
---|
120 | "------------------------------------\n" +
|
---|
121 | "Display range: |z119.4329-Infinity\n" +
|
---|
122 | "Layer default\n" +
|
---|
123 | " * 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" +
|
---|
124 | "\n" +
|
---|
125 | "List of generated Styles:\n" +
|
---|
126 | "-------------------------\n" +
|
---|
127 | " * 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" +
|
---|
128 | "\n" +
|
---|
129 | "\n";
|
---|
130 | // CHECKSTYLE.ON: LineLength
|
---|
131 |
|
---|
132 | try {
|
---|
133 | MainApplication.getLayerManager().addLayer(layer);
|
---|
134 | assertEquals("", InspectPrimitiveDialog.buildMapPaintText());
|
---|
135 | Node n = new Node(LatLon.ZERO);
|
---|
136 | n.setUser(User.getAnonymous());
|
---|
137 | ds.addPrimitive(n);
|
---|
138 | ds.addSelected(n);
|
---|
139 | String text = InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", "");
|
---|
140 | assertEquals(baseText, text);
|
---|
141 | n = new Node(LatLon.ZERO);
|
---|
142 | n.setUser(User.getAnonymous());
|
---|
143 | ds.addPrimitive(n);
|
---|
144 | ds.addSelected(n);
|
---|
145 | assertEquals(baseText + baseText + "The 2 selected objects have identical style caches.\n",
|
---|
146 | InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", ""));
|
---|
147 | } finally {
|
---|
148 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|