Changeset 16933 in josm for trunk/test/unit
- Timestamp:
- 2020-08-26T20:24:32+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java
r16436 r16933 6 6 import static org.junit.Assert.assertNull; 7 7 import static org.junit.Assert.assertTrue; 8 import static org.junit.jupiter.api.Assertions.assertThrows; 8 9 9 10 import java.io.ByteArrayInputStream; … … 13 14 import java.nio.file.Paths; 14 15 import java.util.ArrayList; 16 import java.util.Collection; 15 17 import java.util.List; 16 18 import java.util.Optional; … … 47 49 .doParseDataSet(in, null) 48 50 .getPrimitives(it -> true)); 49 assertEquals(20, primitives.size());50 51 51 final Node node1 = new Node(new LatLon(0.5, 102.0)); 52 final Optional<OsmPrimitive> foundNode1 = primitives.stream() 53 .filter(it -> areEqualNodes(it, node1)) 54 .findFirst(); 55 assertTrue(foundNode1.isPresent()); 56 assertEquals("valueA", foundNode1.get().get("propA")); 52 assertExpectedGeoPrimitives(primitives); 53 } 54 } 57 55 58 final Way way1 = new Way(); 59 way1.addNode(new Node(new LatLon(0.5, 102.0))); 60 way1.addNode(new Node(new LatLon(1, 103))); 61 way1.addNode(new Node(new LatLon(0, 104))); 62 way1.addNode(new Node(new LatLon(1, 105))); 63 final Optional<OsmPrimitive> foundWay1 = primitives.stream() 64 .filter(it -> areEqualWays(it, way1)) 65 .findFirst(); 66 assertTrue(foundWay1.isPresent()); 67 assertEquals("valueB", foundWay1.get().get("propB")); 68 assertEquals("0.0", foundWay1.get().get("propB2")); 69 assertEquals(foundNode1.get(), ((Way) foundWay1.get()).firstNode()); 70 assertEquals("valueA", ((Way) foundWay1.get()).firstNode().get("propA")); 56 /** 57 * Tests reading a GeoJSON file that is line by line separated, per RFC 7464 58 * @throws Exception in case of an error 59 */ 60 @Test 61 public void testReadLineByLineGeoJSON() throws Exception { 62 try (InputStream in = Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "geoLineByLine.json"))) { 63 final List<OsmPrimitive> primitives = new ArrayList<>(new GeoJSONReader() 64 .doParseDataSet(in, null) 65 .getPrimitives(it -> true)); 71 66 72 final Way way2 = new Way(); 73 way2.addNode(new Node(new LatLon(40, 180))); 74 way2.addNode(new Node(new LatLon(50, 180))); 75 way2.addNode(new Node(new LatLon(50, 170))); 76 way2.addNode(new Node(new LatLon(40, 170))); 77 way2.addNode(new Node(new LatLon(40, 180))); 78 final Optional<OsmPrimitive> foundWay2 = primitives.stream() 79 .filter(it -> areEqualWays(it, way2)) 80 .findFirst(); 81 assertTrue(foundWay2.isPresent()); 82 assertEquals( 83 ((Way) foundWay2.get()).getNode(0), 84 ((Way) foundWay2.get()).getNode(((Way) foundWay2.get()).getNodesCount() - 1) 85 ); 67 assertExpectedGeoPrimitives(primitives); 68 } 69 } 86 70 87 final Way way3 = new Way(); 88 way3.addNode(new Node(new LatLon(40, -170))); 89 way3.addNode(new Node(new LatLon(50, -170))); 90 way3.addNode(new Node(new LatLon(50, -180))); 91 way3.addNode(new Node(new LatLon(40, -180))); 92 way3.addNode(new Node(new LatLon(40, -170))); 93 final Optional<OsmPrimitive> foundWay3 = primitives.stream() 94 .filter(it -> areEqualWays(it, way3)) 95 .findFirst(); 96 assertTrue(foundWay3.isPresent()); 97 assertEquals( 98 ((Way) foundWay3.get()).getNode(0), 99 ((Way) foundWay3.get()).getNode(((Way) foundWay3.get()).getNodesCount() - 1) 100 ); 71 private void assertExpectedGeoPrimitives(Collection<OsmPrimitive> primitives) { 72 assertEquals(20, primitives.size()); 101 73 102 final Way way4 = new Way(); 103 way4.addNode(new Node(new LatLon(0, 100))); 104 way4.addNode(new Node(new LatLon(0, 101))); 105 way4.addNode(new Node(new LatLon(1, 101))); 106 way4.addNode(new Node(new LatLon(1, 100))); 107 way4.addNode(new Node(new LatLon(0, 100))); 108 final Optional<OsmPrimitive> foundWay4 = primitives.stream() 109 .filter(it -> areEqualWays(it, way4)) 110 .findFirst(); 111 assertTrue(foundWay4.isPresent()); 112 assertEquals( 113 ((Way) foundWay4.get()).getNode(0), 114 ((Way) foundWay4.get()).getNode(((Way) foundWay4.get()).getNodesCount() - 1) 115 ); 116 assertEquals("valueD", foundWay4.get().get("propD")); 117 assertFalse(foundWay4.get().hasTag("propD2")); 118 assertEquals("true", foundWay4.get().get("propD3")); 119 assertFalse(foundWay4.get().hasKey("propD4")); 120 assertNull(foundWay4.get().get("propD4")); 121 } 74 final Node node1 = new Node(new LatLon(0.5, 102.0)); 75 final Optional<OsmPrimitive> foundNode1 = primitives.stream() 76 .filter(it -> areEqualNodes(it, node1)) 77 .findFirst(); 78 assertTrue(foundNode1.isPresent()); 79 assertEquals("valueA", foundNode1.get().get("propA")); 80 81 final Way way1 = new Way(); 82 way1.addNode(new Node(new LatLon(0.5, 102.0))); 83 way1.addNode(new Node(new LatLon(1, 103))); 84 way1.addNode(new Node(new LatLon(0, 104))); 85 way1.addNode(new Node(new LatLon(1, 105))); 86 final Optional<OsmPrimitive> foundWay1 = primitives.stream() 87 .filter(it -> areEqualWays(it, way1)) 88 .findFirst(); 89 assertTrue(foundWay1.isPresent()); 90 assertEquals("valueB", foundWay1.get().get("propB")); 91 assertEquals("0.0", foundWay1.get().get("propB2")); 92 assertEquals(foundNode1.get(), ((Way) foundWay1.get()).firstNode()); 93 assertEquals("valueA", ((Way) foundWay1.get()).firstNode().get("propA")); 94 95 final Way way2 = new Way(); 96 way2.addNode(new Node(new LatLon(40, 180))); 97 way2.addNode(new Node(new LatLon(50, 180))); 98 way2.addNode(new Node(new LatLon(50, 170))); 99 way2.addNode(new Node(new LatLon(40, 170))); 100 way2.addNode(new Node(new LatLon(40, 180))); 101 final Optional<OsmPrimitive> foundWay2 = primitives.stream() 102 .filter(it -> areEqualWays(it, way2)) 103 .findFirst(); 104 assertTrue(foundWay2.isPresent()); 105 assertEquals( 106 ((Way) foundWay2.get()).getNode(0), 107 ((Way) foundWay2.get()).getNode(((Way) foundWay2.get()).getNodesCount() - 1) 108 ); 109 110 final Way way3 = new Way(); 111 way3.addNode(new Node(new LatLon(40, -170))); 112 way3.addNode(new Node(new LatLon(50, -170))); 113 way3.addNode(new Node(new LatLon(50, -180))); 114 way3.addNode(new Node(new LatLon(40, -180))); 115 way3.addNode(new Node(new LatLon(40, -170))); 116 final Optional<OsmPrimitive> foundWay3 = primitives.stream() 117 .filter(it -> areEqualWays(it, way3)) 118 .findFirst(); 119 assertTrue(foundWay3.isPresent()); 120 assertEquals( 121 ((Way) foundWay3.get()).getNode(0), 122 ((Way) foundWay3.get()).getNode(((Way) foundWay3.get()).getNodesCount() - 1) 123 ); 124 125 final Way way4 = new Way(); 126 way4.addNode(new Node(new LatLon(0, 100))); 127 way4.addNode(new Node(new LatLon(0, 101))); 128 way4.addNode(new Node(new LatLon(1, 101))); 129 way4.addNode(new Node(new LatLon(1, 100))); 130 way4.addNode(new Node(new LatLon(0, 100))); 131 final Optional<OsmPrimitive> foundWay4 = primitives.stream() 132 .filter(it -> areEqualWays(it, way4)) 133 .findFirst(); 134 assertTrue(foundWay4.isPresent()); 135 assertEquals( 136 ((Way) foundWay4.get()).getNode(0), 137 ((Way) foundWay4.get()).getNode(((Way) foundWay4.get()).getNodesCount() - 1) 138 ); 139 assertEquals("valueD", foundWay4.get().get("propD")); 140 assertFalse(foundWay4.get().hasTag("propD2")); 141 assertEquals("true", foundWay4.get().get("propD3")); 142 assertFalse(foundWay4.get().hasKey("propD4")); 143 assertNull(foundWay4.get().get("propD4")); 122 144 } 123 145 … … 140 162 /** 141 163 * Test reading a JSON file which is not a proper GeoJSON (type missing). 142 * @throws IllegalDataException always143 164 */ 144 @Test(expected = IllegalDataException.class)145 public void testReadGeoJsonWithoutType() throws IllegalDataException {146 new GeoJSONReader().doParseDataSet(new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)), null);165 public void testReadGeoJsonWithoutType() { 166 assertThrows(IllegalDataException.class, () -> 167 new GeoJSONReader().doParseDataSet(new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)), null)); 147 168 } 148 169
Note:
See TracChangeset
for help on using the changeset viewer.