Changeset 18619 in josm for trunk/test
- Timestamp:
- 2022-12-27T16:51:43+01:00 (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/SharpAnglesTest.java
r17275 r18619 2 2 package org.openstreetmap.josm.data.validation.tests; 3 3 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 5 10 import org.junit.jupiter.api.BeforeEach; 6 11 import 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; 7 15 import org.openstreetmap.josm.JOSMFixture; 8 16 import org.openstreetmap.josm.TestUtils; 17 import org.openstreetmap.josm.data.coor.EastNorth; 9 18 import org.openstreetmap.josm.data.coor.LatLon; 10 19 import org.openstreetmap.josm.data.osm.Node; 11 20 import org.openstreetmap.josm.data.osm.Way; 21 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 12 22 13 23 /** 14 24 * JUnit Test of the Sharp Angles validation test. 15 25 */ 26 @BasicPreferences 16 27 class SharpAnglesTest { 17 28 private SharpAngles angles; … … 38 49 way.addNode(way.firstNode()); 39 50 angles.visit(way); 40 Assert.assertEquals(0, angles.getErrors().size());51 assertEquals(0, angles.getErrors().size()); 41 52 } 42 53 … … 52 63 angles.setMaxLength(Double.MAX_VALUE); 53 64 angles.visit(way); 54 Assert.assertEquals(1, angles.getErrors().size());65 assertEquals(1, angles.getErrors().size()); 55 66 } 56 67 … … 67 78 angles.setMaxLength(Double.MAX_VALUE); 68 79 angles.visit(way); 69 Assert.assertEquals(2, angles.getErrors().size());80 assertEquals(2, angles.getErrors().size()); 70 81 } 71 82 … … 79 90 new Node(new LatLon(0.2, 0.3)), new Node(new LatLon(0.3, 0.1))); 80 91 angles.visit(way); 81 Assert.assertEquals(0, angles.getErrors().size());92 assertEquals(0, angles.getErrors().size()); 82 93 } 83 94 … … 98 109 way.addNode(way.firstNode()); 99 110 angles.visit(way); 100 Assert.assertEquals(0, angles.getErrors().size());111 assertEquals(0, angles.getErrors().size()); 101 112 } 102 113 … … 111 122 angles.setMaxLength(Double.MAX_VALUE); 112 123 angles.visit(way); 113 Assert.assertEquals(1, angles.getErrors().size());124 assertEquals(1, angles.getErrors().size()); 114 125 angles.getErrors().clear(); 115 126 116 127 way.put("highway", "rest_area"); 117 128 angles.visit(way); 118 Assert.assertEquals(0, angles.getErrors().size());129 assertEquals(0, angles.getErrors().size()); 119 130 120 131 way.put("highway", "residential"); 121 132 angles.visit(way); 122 Assert.assertEquals(1, angles.getErrors().size());133 assertEquals(1, angles.getErrors().size()); 123 134 angles.getErrors().clear(); 124 135 way.put("area", "yes"); 125 136 angles.visit(way); 126 Assert.assertEquals(0, angles.getErrors().size());137 assertEquals(0, angles.getErrors().size()); 127 138 way.put("area", "no"); 128 139 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 } 130 174 } 131 175 }
Note:
See TracChangeset
for help on using the changeset viewer.