1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
15 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
16 | import org.openstreetmap.josm.data.osm.Node;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.data.osm.WaySegment;
|
---|
19 | import org.openstreetmap.josm.data.validation.tests.CrossingWays.Boundaries;
|
---|
20 | import org.openstreetmap.josm.data.validation.tests.CrossingWays.SelfCrossing;
|
---|
21 | import org.openstreetmap.josm.data.validation.tests.CrossingWays.Ways;
|
---|
22 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
23 |
|
---|
24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Unit test of {@link CrossingWays}.
|
---|
28 | */
|
---|
29 | public class CrossingWaysTest {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Setup test
|
---|
33 | */
|
---|
34 | @Rule
|
---|
35 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
36 | public JOSMTestRules rule = new JOSMTestRules().preferences();
|
---|
37 |
|
---|
38 | private static Way newUsableWay(String tags) {
|
---|
39 | return TestUtils.newWay(tags, new Node(LatLon.NORTH_POLE), new Node(LatLon.ZERO));
|
---|
40 | }
|
---|
41 |
|
---|
42 | private static void testMessage(int code, CrossingWays test, String tags1, String tags2) {
|
---|
43 | assertEquals(code, test.createMessage(TestUtils.newWay(tags1), TestUtils.newWay(tags2)).code);
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test of {@link CrossingWays#getSegments}
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | public void testGetSegments() {
|
---|
51 | List<List<WaySegment>> list = CrossingWays.getSegments(new HashMap<>(), EastNorth.ZERO, EastNorth.ZERO);
|
---|
52 | assertEquals(1, list.size());
|
---|
53 | assertTrue(list.get(0).isEmpty());
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Unit test of {@link CrossingWays#isCoastline}
|
---|
58 | */
|
---|
59 | @Test
|
---|
60 | public void testIsCoastline() {
|
---|
61 | assertTrue(CrossingWays.isCoastline(TestUtils.newWay("natural=water")));
|
---|
62 | assertTrue(CrossingWays.isCoastline(TestUtils.newWay("natural=coastline")));
|
---|
63 | assertTrue(CrossingWays.isCoastline(TestUtils.newWay("landuse=reservoir")));
|
---|
64 | assertFalse(CrossingWays.isCoastline(TestUtils.newWay("landuse=military")));
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Unit test of {@link CrossingWays#isHighway}
|
---|
69 | */
|
---|
70 | @Test
|
---|
71 | public void testIsHighway() {
|
---|
72 | assertTrue(CrossingWays.isHighway(TestUtils.newWay("highway=motorway")));
|
---|
73 | assertFalse(CrossingWays.isHighway(TestUtils.newWay("highway=rest_area")));
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Unit test of {@link CrossingWays#isRailway}
|
---|
78 | */
|
---|
79 | @Test
|
---|
80 | public void testIsRailway() {
|
---|
81 | assertTrue(CrossingWays.isRailway(TestUtils.newWay("railway=rail")));
|
---|
82 | assertFalse(CrossingWays.isRailway(TestUtils.newWay("railway=subway")));
|
---|
83 | assertFalse(CrossingWays.isRailway(TestUtils.newWay("highway=motorway")));
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Unit test of {@link CrossingWays#isSubwayOrTramOrRazed}
|
---|
88 | */
|
---|
89 | @Test
|
---|
90 | public void testIsSubwayOrTramOrRazed() {
|
---|
91 | assertTrue(CrossingWays.isSubwayOrTramOrRazed(TestUtils.newWay("railway=subway")));
|
---|
92 | assertTrue(CrossingWays.isSubwayOrTramOrRazed(TestUtils.newWay("railway=construction construction=tram")));
|
---|
93 | assertTrue(CrossingWays.isSubwayOrTramOrRazed(TestUtils.newWay("railway=disused disused=tram")));
|
---|
94 | assertFalse(CrossingWays.isSubwayOrTramOrRazed(TestUtils.newWay("railway=construction")));
|
---|
95 | assertFalse(CrossingWays.isSubwayOrTramOrRazed(TestUtils.newWay("railway=disused")));
|
---|
96 | assertFalse(CrossingWays.isSubwayOrTramOrRazed(TestUtils.newWay("railway=rail")));
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Unit test of {@link CrossingWays#isProposedOrAbandoned}
|
---|
101 | */
|
---|
102 | @Test
|
---|
103 | public void testIsProposedOrAbandoned() {
|
---|
104 | assertTrue(CrossingWays.isProposedOrAbandoned(TestUtils.newWay("highway=proposed")));
|
---|
105 | assertTrue(CrossingWays.isProposedOrAbandoned(TestUtils.newWay("railway=proposed")));
|
---|
106 | assertTrue(CrossingWays.isProposedOrAbandoned(TestUtils.newWay("railway=abandoned")));
|
---|
107 | assertFalse(CrossingWays.isProposedOrAbandoned(TestUtils.newWay("highway=motorway")));
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Unit test of {@link CrossingWays.Ways}
|
---|
112 | */
|
---|
113 | @Test
|
---|
114 | public void testWays() {
|
---|
115 | Ways test = new CrossingWays.Ways();
|
---|
116 | // isPrimitiveUsable
|
---|
117 | assertFalse(test.isPrimitiveUsable(newUsableWay("amenity=restaurant")));
|
---|
118 | assertFalse(test.isPrimitiveUsable(newUsableWay("highway=proposed")));
|
---|
119 | assertFalse(test.isPrimitiveUsable(TestUtils.newWay("highway=motorway"))); // Unusable (0 node)
|
---|
120 | assertTrue(test.isPrimitiveUsable(newUsableWay("highway=motorway"))); // Usable (2 nodes)
|
---|
121 | assertTrue(test.isPrimitiveUsable(newUsableWay("waterway=river")));
|
---|
122 | assertTrue(test.isPrimitiveUsable(newUsableWay("railway=rail")));
|
---|
123 | assertTrue(test.isPrimitiveUsable(newUsableWay("natural=water")));
|
---|
124 | assertTrue(test.isPrimitiveUsable(newUsableWay("building=yes")));
|
---|
125 | assertTrue(test.isPrimitiveUsable(newUsableWay("landuse=residential")));
|
---|
126 | // createMessage
|
---|
127 | testMessage(601, test, "amenity=restaurant", "amenity=restaurant");
|
---|
128 | testMessage(611, test, "building=yes", "amenity=restaurant");
|
---|
129 | testMessage(612, test, "building=yes", "highway=road");
|
---|
130 | testMessage(613, test, "building=yes", "railway=rail");
|
---|
131 | testMessage(614, test, "building=yes", "landuse=residential");
|
---|
132 | testMessage(615, test, "building=yes", "waterway=river");
|
---|
133 | testMessage(620, test, "highway=road", "highway=road");
|
---|
134 | testMessage(621, test, "highway=road", "amenity=restaurant");
|
---|
135 | testMessage(622, test, "highway=road", "railway=rail");
|
---|
136 | testMessage(623, test, "highway=road", "waterway=river");
|
---|
137 | testMessage(630, test, "railway=rail", "railway=rail");
|
---|
138 | testMessage(631, test, "railway=rail", "amenity=restaurant");
|
---|
139 | testMessage(632, test, "railway=rail", "waterway=river");
|
---|
140 | testMessage(641, test, "landuse=residential", "amenity=restaurant");
|
---|
141 | testMessage(650, test, "waterway=river", "waterway=river");
|
---|
142 | testMessage(651, test, "waterway=river", "amenity=restaurant");
|
---|
143 | testMessage(603, test, "barrier=hedge", "barrier=yes");
|
---|
144 | testMessage(661, test, "barrier=hedge", "building=yes");
|
---|
145 | testMessage(662, test, "barrier=hedge", "highway=road");
|
---|
146 | testMessage(663, test, "barrier=hedge", "railway=rail");
|
---|
147 | testMessage(664, test, "barrier=hedge", "waterway=river");
|
---|
148 |
|
---|
149 | assertFalse(test.isPrimitiveUsable(newUsableWay("amenity=restaurant")));
|
---|
150 | assertFalse(test.isPrimitiveUsable(TestUtils.newWay("barrier=yes"))); // Unusable (0 node)
|
---|
151 | assertTrue(test.isPrimitiveUsable(newUsableWay("barrier=yes"))); // Usable (2 nodes)
|
---|
152 |
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Unit test of {@link CrossingWays.Boundaries}
|
---|
157 | */
|
---|
158 | @Test
|
---|
159 | public void testBoundaries() {
|
---|
160 | Boundaries test = new CrossingWays.Boundaries();
|
---|
161 | // isPrimitiveUsable
|
---|
162 | assertFalse(test.isPrimitiveUsable(newUsableWay("amenity=restaurant")));
|
---|
163 | assertFalse(test.isPrimitiveUsable(TestUtils.newWay("boudary=administrative"))); // Unusable (0 node)
|
---|
164 | assertTrue(test.isPrimitiveUsable(newUsableWay("boundary=administrative"))); // Usable (2 nodes)
|
---|
165 | assertFalse(test.isPrimitiveUsable(TestUtils.newRelation("boundary=administrative")));
|
---|
166 | assertTrue(test.isPrimitiveUsable(TestUtils.newRelation("boundary=administrative type=multipolygon")));
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Unit test of {@link CrossingWays.SelfCrossing}
|
---|
171 | */
|
---|
172 | @Test
|
---|
173 | public void testSelfCrossing() {
|
---|
174 | SelfCrossing test = new CrossingWays.SelfCrossing();
|
---|
175 | // isPrimitiveUsable
|
---|
176 | assertFalse(test.isPrimitiveUsable(newUsableWay("highway=motorway")));
|
---|
177 | assertFalse(test.isPrimitiveUsable(newUsableWay("barrier=yes")));
|
---|
178 | assertFalse(test.isPrimitiveUsable(newUsableWay("boundary=administrative")));
|
---|
179 | assertFalse(test.isPrimitiveUsable(TestUtils.newWay("amenity=restaurant"))); // Unusable (0 node)
|
---|
180 | assertTrue(test.isPrimitiveUsable(newUsableWay("amenity=restaurant"))); // Usable (2 nodes)
|
---|
181 | }
|
---|
182 | }
|
---|