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 | assertEquals("", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.allPrimitives())));
|
---|
50 | Node n = new Node(LatLon.ZERO);
|
---|
51 | n.setOsmId(1, 1);
|
---|
52 | ds.addPrimitive(n);
|
---|
53 | assertEquals(
|
---|
54 | "Node: 1\n" +
|
---|
55 | " Data Set: "+Integer.toHexString(ds.hashCode())+"\n" +
|
---|
56 | " Edited at: <new object>\n" +
|
---|
57 | " Edited by: <new object>\n" +
|
---|
58 | " Version: 1\n" +
|
---|
59 | " In changeset: 0\n" +
|
---|
60 | " Coordinates: 0.0, 0.0\n" +
|
---|
61 | " Coordinates (projected): 0.0, -7.081154551613622E-10\n" +
|
---|
62 | "\n", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.allPrimitives())));
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Unit test of {@link InspectPrimitiveDialog#buildListOfEditorsText}.
|
---|
67 | */
|
---|
68 | @Test
|
---|
69 | public void testBuildListOfEditorsText() {
|
---|
70 | DataSet ds = new DataSet();
|
---|
71 | assertEquals("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
72 | ds.addPrimitive(new Node(LatLon.ZERO));
|
---|
73 | assertEquals("0 users last edited the selection:\n\n", InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
74 | Node n = new Node(LatLon.ZERO);
|
---|
75 | n.setUser(User.getAnonymous());
|
---|
76 | ds.addPrimitive(n);
|
---|
77 | n = new Node(LatLon.ZERO);
|
---|
78 | n.setUser(User.getAnonymous());
|
---|
79 | ds.addPrimitive(n);
|
---|
80 | assertEquals(
|
---|
81 | "1 user last edited the selection:\n" +
|
---|
82 | "\n" +
|
---|
83 | " 2 <anonymous>\n",
|
---|
84 | InspectPrimitiveDialog.buildListOfEditorsText(ds.allPrimitives()));
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Unit test of {@link InspectPrimitiveDialog#buildMapPaintText}.
|
---|
89 | */
|
---|
90 | @Test
|
---|
91 | public void testBuildMapPaintText() {
|
---|
92 | DataSet ds = new DataSet();
|
---|
93 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
94 |
|
---|
95 | // CHECKSTYLE.OFF: LineLength
|
---|
96 | String baseText =
|
---|
97 | "Styles Cache for \"node\":\n" +
|
---|
98 | "\n" +
|
---|
99 | "> applying mapcss style \"JOSM default (MapCSS)\"\n" +
|
---|
100 | "\n" +
|
---|
101 | "Range:|s119.4328566955879-Infinity\n" +
|
---|
102 | " default: \n" +
|
---|
103 | "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" +
|
---|
104 | "\n" +
|
---|
105 | "> skipping \"Potlatch 2\" (not active)\n" +
|
---|
106 | "\n" +
|
---|
107 | "List of generated Styles:\n" +
|
---|
108 | " * 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" +
|
---|
109 | "\n" +
|
---|
110 | "\n";
|
---|
111 | // CHECKSTYLE.ON: LineLength
|
---|
112 |
|
---|
113 | try {
|
---|
114 | MainApplication.getLayerManager().addLayer(layer);
|
---|
115 | assertEquals("", InspectPrimitiveDialog.buildMapPaintText());
|
---|
116 | Node n = new Node(LatLon.ZERO);
|
---|
117 | n.setUser(User.getAnonymous());
|
---|
118 | ds.addPrimitive(n);
|
---|
119 | ds.addSelected(n);
|
---|
120 | String text = InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", "");
|
---|
121 | assertEquals(baseText, text);
|
---|
122 | n = new Node(LatLon.ZERO);
|
---|
123 | n.setUser(User.getAnonymous());
|
---|
124 | ds.addPrimitive(n);
|
---|
125 | ds.addSelected(n);
|
---|
126 | assertEquals(baseText + baseText + "The 2 selected objects have identical style caches.",
|
---|
127 | InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", ""));
|
---|
128 | } finally {
|
---|
129 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|