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.gui.MainApplication;
|
---|
18 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests of {@link InspectPrimitiveDialog} class.
|
---|
25 | */
|
---|
26 | public class InspectPrimitiveDialogTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup tests
|
---|
30 | */
|
---|
31 | @Rule
|
---|
32 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
33 | public JOSMTestRules test = new JOSMTestRules().main().platform().projection().mapStyles();
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Unit test of {@link InspectPrimitiveDialog#genericMonospacePanel}.
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void testGenericMonospacePanel() {
|
---|
40 | assertNotNull(InspectPrimitiveDialog.genericMonospacePanel(new JPanel(), ""));
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Unit test of {@link InspectPrimitiveDialog#buildDataText}.
|
---|
45 | */
|
---|
46 | @Test
|
---|
47 | public void testBuildDataText() {
|
---|
48 | DataSet ds = new DataSet();
|
---|
49 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
50 | assertEquals("", InspectPrimitiveDialog.buildDataText(layer, new ArrayList<>(ds.allPrimitives())));
|
---|
51 | Node n = new Node(LatLon.ZERO);
|
---|
52 | n.setOsmId(1, 1);
|
---|
53 | ds.addPrimitive(n);
|
---|
54 | assertEquals(
|
---|
55 | "Node: 1\n" +
|
---|
56 | " Data Set: "+Integer.toHexString(ds.hashCode())+"\n" +
|
---|
57 | " Edited at: <new object>\n" +
|
---|
58 | " Edited by: <new object>\n" +
|
---|
59 | " Version: 1\n" +
|
---|
60 | " In changeset: 0\n" +
|
---|
61 | " Coordinates: 0.0, 0.0\n" +
|
---|
62 | " Coordinates (projected): 0.0, -7.081154551613622E-10\n" +
|
---|
63 | "\n", InspectPrimitiveDialog.buildDataText(layer, new ArrayList<>(ds.allPrimitives())));
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Unit test of {@link InspectPrimitiveDialog#buildListOfEditorsText}.
|
---|
68 | */
|
---|
69 | @Test
|
---|
70 | public void testBuildListOfEditorsText() {
|
---|
71 | DataSet ds = new DataSet();
|
---|
72 | assertEquals("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
73 | ds.addPrimitive(new Node(LatLon.ZERO));
|
---|
74 | assertEquals("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
75 | Node n = new Node(LatLon.ZERO);
|
---|
76 | n.setUser(User.getAnonymous());
|
---|
77 | ds.addPrimitive(n);
|
---|
78 | n = new Node(LatLon.ZERO);
|
---|
79 | n.setUser(User.getAnonymous());
|
---|
80 | ds.addPrimitive(n);
|
---|
81 | assertEquals(
|
---|
82 | "1 user last edited the selection:\n" +
|
---|
83 | "\n" +
|
---|
84 | " 2 <anonymous>\n",
|
---|
85 | InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Unit test of {@link InspectPrimitiveDialog#buildMapPaintText}.
|
---|
90 | */
|
---|
91 | @Test
|
---|
92 | public void testBuildMapPaintText() {
|
---|
93 | DataSet ds = new DataSet();
|
---|
94 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
95 |
|
---|
96 | // CHECKSTYLE.OFF: LineLength
|
---|
97 | String baseText =
|
---|
98 | "Styles Cache for \"node (0.0, 0.0)\":\n" +
|
---|
99 | "\n" +
|
---|
100 | "> applying mapcss style \"JOSM default (MapCSS)\"\n" +
|
---|
101 | "\n" +
|
---|
102 | "Range:|s119.4328566955879-Infinity\n" +
|
---|
103 | " default: \n" +
|
---|
104 | "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" +
|
---|
105 | "\n" +
|
---|
106 | "> skipping \"Potlatch 2\" (not active)\n" +
|
---|
107 | "\n" +
|
---|
108 | "List of generated Styles:\n" +
|
---|
109 | " * 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" +
|
---|
110 | "\n" +
|
---|
111 | "\n";
|
---|
112 | // CHECKSTYLE.ON: LineLength
|
---|
113 |
|
---|
114 | try {
|
---|
115 | MainApplication.getLayerManager().addLayer(layer);
|
---|
116 | assertEquals("", InspectPrimitiveDialog.buildMapPaintText());
|
---|
117 | Node n = new Node(LatLon.ZERO);
|
---|
118 | n.setUser(User.getAnonymous());
|
---|
119 | ds.addPrimitive(n);
|
---|
120 | ds.addSelected(n);
|
---|
121 | String text = InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", "");
|
---|
122 | assertEquals(baseText, text);
|
---|
123 | n = new Node(LatLon.ZERO);
|
---|
124 | n.setUser(User.getAnonymous());
|
---|
125 | ds.addPrimitive(n);
|
---|
126 | ds.addSelected(n);
|
---|
127 | assertEquals(baseText + baseText + "The 2 selected objects have identical style caches.",
|
---|
128 | InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", ""));
|
---|
129 | } finally {
|
---|
130 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|