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

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

see #15182 - deprecate Main.getLayerManager(). Replacement: gui.MainApplication.getLayerManager()

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6
7import java.util.ArrayList;
8
9import javax.swing.JPanel;
10
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.User;
17import org.openstreetmap.josm.gui.MainApplication;
18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
19import org.openstreetmap.josm.testutils.JOSMTestRules;
20
21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22
23/**
24 * Unit tests of {@link InspectPrimitiveDialog} class.
25 */
26public 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}
Note: See TracBrowser for help on using the repository browser.