11// License: GPL. For details, see LICENSE file.
22package org .openstreetmap .josm .data .validation .tests ;
33
4- import org .junit .Assert ;
4+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
5+ import static org .junit .jupiter .api .Assertions .assertEquals ;
6+
7+ import java .util .Arrays ;
8+ import java .util .stream .Stream ;
9+
510import org .junit .jupiter .api .BeforeEach ;
611import org .junit .jupiter .api .Test ;
12+ import org .junit .jupiter .params .ParameterizedTest ;
13+ import org .junit .jupiter .params .provider .Arguments ;
14+ import org .junit .jupiter .params .provider .MethodSource ;
715import org .openstreetmap .josm .JOSMFixture ;
816import org .openstreetmap .josm .TestUtils ;
17+ import org .openstreetmap .josm .data .coor .EastNorth ;
918import org .openstreetmap .josm .data .coor .LatLon ;
1019import org .openstreetmap .josm .data .osm .Node ;
1120import org .openstreetmap .josm .data .osm .Way ;
21+ import org .openstreetmap .josm .testutils .annotations .BasicPreferences ;
1222
1323/**
1424 * JUnit Test of the Sharp Angles validation test.
1525 */
26+ @ BasicPreferences
1627class SharpAnglesTest {
1728 private SharpAngles angles ;
1829
@@ -37,7 +48,7 @@ void testClosedLoopNoSharpAngles() {
3748 new Node (new LatLon (0.1 , -0.2 )), new Node (new LatLon (-0.1 , -0.1 )));
3849 way .addNode (way .firstNode ());
3950 angles .visit (way );
40- Assert . assertEquals (0 , angles .getErrors ().size ());
51+ assertEquals (0 , angles .getErrors ().size ());
4152 }
4253
4354 /**
@@ -51,7 +62,7 @@ void testClosedLoopSharpAngles() {
5162 way .addNode (way .firstNode ());
5263 angles .setMaxLength (Double .MAX_VALUE );
5364 angles .visit (way );
54- Assert . assertEquals (1 , angles .getErrors ().size ());
65+ assertEquals (1 , angles .getErrors ().size ());
5566 }
5667
5768 /**
@@ -66,7 +77,7 @@ void testMultipleSharpAngles() {
6677 new Node (new LatLon (0.005031826787678042 , 0.0020116540789620915 )));
6778 angles .setMaxLength (Double .MAX_VALUE );
6879 angles .visit (way );
69- Assert . assertEquals (2 , angles .getErrors ().size ());
80+ assertEquals (2 , angles .getErrors ().size ());
7081 }
7182
7283 /**
@@ -78,7 +89,7 @@ void testNoSharpAngles() {
7889 new Node (new LatLon (0 , 0 )), new Node (new LatLon (0.1 , 0.1 )),
7990 new Node (new LatLon (0.2 , 0.3 )), new Node (new LatLon (0.3 , 0.1 )));
8091 angles .visit (way );
81- Assert . assertEquals (0 , angles .getErrors ().size ());
92+ assertEquals (0 , angles .getErrors ().size ());
8293 }
8394
8495 /**
@@ -97,7 +108,7 @@ void testCheckBadAnglesFromSameNodeTwice() {
97108 new Node (new LatLon (52.8902482 , 8.4307568 )));
98109 way .addNode (way .firstNode ());
99110 angles .visit (way );
100- Assert . assertEquals (0 , angles .getErrors ().size ());
111+ assertEquals (0 , angles .getErrors ().size ());
101112 }
102113
103114 /**
@@ -110,22 +121,55 @@ void testIgnoredCases() {
110121 new Node (new LatLon (0 , 0.01 )));
111122 angles .setMaxLength (Double .MAX_VALUE );
112123 angles .visit (way );
113- Assert . assertEquals (1 , angles .getErrors ().size ());
124+ assertEquals (1 , angles .getErrors ().size ());
114125 angles .getErrors ().clear ();
115126
116127 way .put ("highway" , "rest_area" );
117128 angles .visit (way );
118- Assert . assertEquals (0 , angles .getErrors ().size ());
129+ assertEquals (0 , angles .getErrors ().size ());
119130
120131 way .put ("highway" , "residential" );
121132 angles .visit (way );
122- Assert . assertEquals (1 , angles .getErrors ().size ());
133+ assertEquals (1 , angles .getErrors ().size ());
123134 angles .getErrors ().clear ();
124135 way .put ("area" , "yes" );
125136 angles .visit (way );
126- Assert . assertEquals (0 , angles .getErrors ().size ());
137+ assertEquals (0 , angles .getErrors ().size ());
127138 way .put ("area" , "no" );
128139 angles .visit (way );
129- Assert .assertEquals (1 , angles .getErrors ().size ());
140+ assertEquals (1 , angles .getErrors ().size ());
141+ }
142+
143+ static Stream <Arguments > testNonRegression22600 () {
144+ return Stream .of (
145+ // All invalid nodes
146+ Arguments .of (new Node (), new Node (), new Node ()),
147+ // Single valid nodes
148+ Arguments .of (new Node (LatLon .SOUTH_POLE ), new Node (), new Node ()),
149+ Arguments .of (new Node (), new Node (LatLon .ZERO ), new Node ()),
150+ Arguments .of (new Node (), new Node (), new Node (LatLon .NORTH_POLE )),
151+ // Two valid nodes
152+ Arguments .of (new Node (), new Node (LatLon .ZERO ), new Node (LatLon .NORTH_POLE )),
153+ Arguments .of (new Node (LatLon .SOUTH_POLE ), new Node (LatLon .ZERO ), new Node ()),
154+ Arguments .of (new Node (LatLon .SOUTH_POLE ), new Node (), new Node (LatLon .NORTH_POLE )),
155+ // All valid nodes
156+ Arguments .of (new Node (LatLon .SOUTH_POLE ), new Node (LatLon .ZERO ), new Node (LatLon .NORTH_POLE ))
157+ );
158+ }
159+
160+ /**
161+ * Non-regression test for #22600: NPE: Cannot invoke {@link EastNorth#isValid()} because "common" is null
162+ */
163+ @ ParameterizedTest
164+ @ MethodSource
165+ void testNonRegression22600 (Node node1 , Node node2 , Node node3 ) {
166+ Way invalidWay = new Way ();
167+ invalidWay .put ("highway" , "trunk" );
168+ invalidWay .setNodes (Arrays .asList (node1 , node2 , node3 ));
169+ assertDoesNotThrow (() -> this .angles .visit (invalidWay ));
170+ for (Node node : invalidWay .getNodes ()) {
171+ node .setCoor (LatLon .ZERO );
172+ assertDoesNotThrow (() -> this .angles .visit (invalidWay ));
173+ }
130174 }
131175}
0 commit comments