source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/tests/DuplicateNodeTest.java@ 11747

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

checkstyle - NoWhiteSpaceBefore ...

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.junit.Assert.assertEquals;
5
6import org.junit.Rule;
7import org.junit.Test;
8import org.openstreetmap.josm.data.coor.LatLon;
9import org.openstreetmap.josm.data.osm.DataSet;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Tag;
12import org.openstreetmap.josm.data.osm.Way;
13import org.openstreetmap.josm.data.validation.TestError;
14import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19/**
20 * JUnit Test of "Duplicate node" validation test.
21 */
22public class DuplicateNodeTest {
23
24 /**
25 * Setup test by initializing JOSM preferences and projection.
26 */
27 @Rule
28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
29 public JOSMTestRules test = new JOSMTestRules();
30
31 private static final DuplicateNode TEST = new DuplicateNode();
32
33 private static void doTest(int code, Tag... tags) {
34 performTest(code, buildDataSet(tags), true);
35 }
36
37 private static void performTest(int code, DataSet ds, boolean fixable) {
38 TEST.startTest(NullProgressMonitor.INSTANCE);
39 TEST.visit(ds.allPrimitives());
40 TEST.endTest();
41
42 assertEquals(1, TEST.getErrors().size());
43 TestError error = TEST.getErrors().iterator().next();
44 assertEquals(code, error.getCode());
45 assertEquals(fixable, error.isFixable());
46 }
47
48 private static DataSet buildDataSet(Tag... tags) {
49 DataSet ds = new DataSet();
50
51 Node a = new Node(new LatLon(10.0, 5.0));
52 Node b = new Node(new LatLon(10.0, 5.0));
53 ds.addPrimitive(a);
54 ds.addPrimitive(b);
55
56 if (tags.length > 0) {
57 Way parent = new Way();
58 parent.addNode(a);
59 parent.addNode(b);
60 for (Tag tag : tags) {
61 parent.put(tag);
62 }
63 ds.addPrimitive(parent);
64 }
65 return ds;
66 }
67
68 /**
69 * Test of "Duplicate node" validation test - different tag sets.
70 */
71 @Test
72 public void testDuplicateNode() {
73 DataSet ds = new DataSet();
74
75 Node a = new Node(new LatLon(10.0, 5.0));
76 Node b = new Node(new LatLon(10.0, 5.0));
77 ds.addPrimitive(a);
78 ds.addPrimitive(b);
79
80 a.put("foo", "bar");
81 b.put("bar", "foo");
82
83 performTest(DuplicateNode.DUPLICATE_NODE, ds, false);
84 }
85
86 /**
87 * Test of "Duplicate node" validation test - mixed case.
88 */
89 @Test
90 public void testDuplicateNodeMixed() {
91 doTest(DuplicateNode.DUPLICATE_NODE_MIXED, new Tag("building", "foo"), new Tag("highway", "bar"));
92 }
93
94 /**
95 * Test of "Duplicate node" validation test - other case.
96 */
97 @Test
98 public void testDuplicateNodeOther() {
99 doTest(DuplicateNode.DUPLICATE_NODE_OTHER);
100 }
101
102 /**
103 * Test of "Duplicate node" validation test - building case.
104 */
105 @Test
106 public void testDuplicateNodeBuilding() {
107 doTest(DuplicateNode.DUPLICATE_NODE_BUILDING, new Tag("building", "foo"));
108 }
109
110 /**
111 * Test of "Duplicate node" validation test - boundary case.
112 */
113 @Test
114 public void testDuplicateNodeBoundary() {
115 doTest(DuplicateNode.DUPLICATE_NODE_BOUNDARY, new Tag("boundary", "foo"));
116 }
117
118 /**
119 * Test of "Duplicate node" validation test - highway case.
120 */
121 @Test
122 public void testDuplicateNodeHighway() {
123 doTest(DuplicateNode.DUPLICATE_NODE_HIGHWAY, new Tag("highway", "foo"));
124 }
125
126 /**
127 * Test of "Duplicate node" validation test - landuse case.
128 */
129 @Test
130 public void testDuplicateNodeLanduse() {
131 doTest(DuplicateNode.DUPLICATE_NODE_LANDUSE, new Tag("landuse", "foo"));
132 }
133
134 /**
135 * Test of "Duplicate node" validation test - natural case.
136 */
137 @Test
138 public void testDuplicateNodeNatural() {
139 doTest(DuplicateNode.DUPLICATE_NODE_NATURAL, new Tag("natural", "foo"));
140 }
141
142 /**
143 * Test of "Duplicate node" validation test - power case.
144 */
145 @Test
146 public void testDuplicateNodePower() {
147 doTest(DuplicateNode.DUPLICATE_NODE_POWER, new Tag("power", "foo"));
148 }
149
150 /**
151 * Test of "Duplicate node" validation test - railway case.
152 */
153 @Test
154 public void testDuplicateNodeRailway() {
155 doTest(DuplicateNode.DUPLICATE_NODE_RAILWAY, new Tag("railway", "foo"));
156 }
157
158 /**
159 * Test of "Duplicate node" validation test - waterway case.
160 */
161 @Test
162 public void testDuplicateNodeWaterway() {
163 doTest(DuplicateNode.DUPLICATE_NODE_WATERWAY, new Tag("waterway", "foo"));
164 }
165}
Note: See TracBrowser for help on using the repository browser.