diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java index 4fd774887..316357f57 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java @@ -45,11 +45,14 @@ public static void breakDownClass() throws SQLException { IterateAllTest.conn.close(); } - public IterateAllTest() {} + public IterateAllTest() { + } @Test - public void testIssue108() throws SQLException, IOException, ClassNotFoundException, ParseException, OSHDBKeytablesNotFoundException { - ResultSet oshCellsRawData = conn.prepareStatement("select data from " + TableNames.T_NODES).executeQuery(); + public void testIssue108() throws SQLException, IOException, ClassNotFoundException, + ParseException, OSHDBKeytablesNotFoundException { + ResultSet oshCellsRawData = conn.prepareStatement( + "select data from " + TableNames.T_NODES).executeQuery(); int countTotal = 0; int countCreated = 0; @@ -78,10 +81,11 @@ public void testIssue108() throws SQLException, IOException, ClassNotFoundExcept ).collect(Collectors.toList()); countTotal += result.size(); for (IterateAllEntry entry : result) { - if (entry.activities.contains(ContributionType.CREATION)) + if (entry.activities.contains(ContributionType.CREATION)) { countCreated++; - else + } else { countOther++; + } } } } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java index db529dc35..38b0fcf4d 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -20,10 +24,6 @@ import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionNodesTest { private GridOSHNodes oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -412,13 +412,13 @@ public void testTagChangeTagFilterWithoutSuccess() { @Test public void testPolygonIntersectingDataPartly() { // lon lat changes, so that node in v2 is outside bbox - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -440,13 +440,14 @@ public void testPolygonIntersectingDataPartly() { @Test public void testTagFilterAndPolygonIntersectingDataPartly() { // lon lat changes, so that node in v2 is outside bbox - GeometryFactory geometryFactory = new GeometryFactory(); // create clipping polygon for area of interest - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + // create clipping polygon for area of interest + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -457,24 +458,25 @@ public void testTagFilterAndPolygonIntersectingDataPartly() { polygonFromCoordinates,// clipping polygon areaDecider, oshEntity -> oshEntity.getId() == 6, - osmEntity -> osmEntity.hasTagKey(osmXmlTestData.keys().get("shop")),// filter entity for tag = shop + // filter entity for tag = shop + osmEntity -> osmEntity.hasTagKey(osmXmlTestData.keys().get("shop")), false )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); // result size =2 becuase if tag filtered for disappears it's a deletion - assertEquals(2,result.size());// one version with tag shop + assertEquals(2,result.size()); // one version with tag shop } @Test public void testCoordinatesRelativeToPolygon() throws IOException { - //different cases of relative position between node coordinate(s) and cell bbox / query polygon - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(0.0,0.0); - coords[1]=new Coordinate(1.5,0.0); - coords[2]=new Coordinate(0.0,1.5); - coords[3]=new Coordinate(0.0,0.0); + // different cases of relative position between node coordinate(s) and cell bbox / query polygon + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(0.0,0.0); + coords[1] = new Coordinate(1.5,0.0); + coords[2] = new Coordinate(0.0,1.5); + coords[3] = new Coordinate(0.0,0.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -487,9 +489,8 @@ public void testCoordinatesRelativeToPolygon() throws IOException { oshEntity -> oshEntity.getId() >= 10 && oshEntity.getId() < 20, osmEntity -> true, false - )).iterateByContribution( - GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)).getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/) - ).collect(Collectors.toList()); + )).iterateByContribution(GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)) + .getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/)).collect(Collectors.toList()); assertEquals(2, result.size()); assertTrue(result.get(0).osmEntity.getId() == 13); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java index 7cf275c42..9c837295f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertTrue; + import com.google.common.collect.Lists; import java.io.IOException; import java.util.Collections; @@ -18,14 +20,12 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertTrue; - public class IterateByContributionNotOsmTypeSpecificTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; private final List oshRelations; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public IterateByContributionNotOsmTypeSpecificTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm"); @@ -36,16 +36,16 @@ public IterateByContributionNotOsmTypeSpecificTest() throws IOException { @Test public void testCellOutsidePolygon() throws IOException { - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, Collections - .emptyList()); - - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,12.7); - coords[2]=new Coordinate(12.7,12.7); - coords[3]=new Coordinate(12.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + Collections.emptyList()); + + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,12.7); + coords[2] = new Coordinate(12.7,12.7); + coords[3] = new Coordinate(12.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( @@ -63,17 +63,19 @@ public void testCellOutsidePolygon() throws IOException { ).collect(Collectors.toList()); assertTrue(resultPoly.isEmpty()); } + @Test public void testCellCoveringPolygon() throws IOException { - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, oshRelations); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, + oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); + final GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(12.7,12.7); - coords[2]=new Coordinate(12.7,10.3); - coords[3]=new Coordinate(10.8,10.3); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(12.7,12.7); + coords[2] = new Coordinate(12.7,10.3); + coords[3] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( @@ -94,16 +96,17 @@ public void testCellCoveringPolygon() throws IOException { @Test public void testCellFullyInsidePolygon() throws IOException { - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, oshRelations); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); + final GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java index 43b18c800..d76c4466f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -20,16 +25,11 @@ import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Polygon; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionRelationsTest { private GridOSHRelations oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public IterateByContributionRelationsTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm");// read osm xml data @@ -44,19 +44,23 @@ public void testGeometryChange() { // relation: creation and two geometry changes, but no tag changes // relation getting more ways, one disappears List result = (new CellIterator( + // get in this time interval every contribution new OSHDBTimestamps( "2000-01-01T00:00:00Z", "2020-01-01T00:00:00Z" - ).get(),// get in this timeinterval every contribution - new OSHDBBoundingBox(-180,-90, 180, 90),// look at dat in this bbox - areaDecider,// needed to create actual geometries from OSM data - oshEntity -> oshEntity.getId() == 500,// oshEntityPreFilter: get data of relation with id 500 + ).get(), + // look at dat in this bbox + new OSHDBBoundingBox(-180,-90, 180, 90), + // needed to create actual geometries from OSM data + areaDecider, + // oshEntityPreFilter: get data of relation with id 500 + oshEntity -> oshEntity.getId() == 500, osmEntity -> true,// osmEntityFilter: true -> get all false )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - // one creation and two gemotry changes should give a result with 3 elements + // one creation and two geomotry changes should give a result with 3 elements assertEquals(3, result.size()); // check if the contribution types are correct assertEquals( @@ -133,8 +137,7 @@ public void testWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -342,8 +345,7 @@ public void testNodesOfWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -613,13 +615,13 @@ public void testWaySplitUpInTwo() { @Test public void testPolygonIntersectingDataPartly() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -641,13 +643,13 @@ public void testPolygonIntersectingDataPartly() { @Test public void testPolygonIntersectingDataOnlyAtBorderLine() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.7,10.4); - coords[1]=new Coordinate(10.94,10.4); - coords[2]=new Coordinate(10.94,10.9); - coords[3]=new Coordinate(10.7,10.9); - coords[4]=new Coordinate(10.7,10.4); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.7,10.4); + coords[1] = new Coordinate(10.94,10.4); + coords[2] = new Coordinate(10.94,10.9); + coords[3] = new Coordinate(10.7,10.9); + coords[4] = new Coordinate(10.7,10.4); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -669,13 +671,13 @@ public void testPolygonIntersectingDataOnlyAtBorderLine() { @Test public void testPolygonIntersectingDataCompletely() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -697,13 +699,13 @@ public void testPolygonIntersectingDataCompletely() { @Test public void testPolygonNotIntersectingData() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(48,49); - coords[1]=new Coordinate(48 ,50); - coords[2]=new Coordinate(49,50); - coords[3]=new Coordinate(49,49); - coords[4]=new Coordinate(48,49); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(48,49); + coords[1] = new Coordinate(48,50); + coords[2] = new Coordinate(49,50); + coords[3] = new Coordinate(49,49); + coords[4] = new Coordinate(48,49); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -755,13 +757,13 @@ public void testNodeChangeOutsideBbox() { @Test public void testPolygonIntersectingDataCompletelyTimeIntervalAfterChanges() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -860,13 +862,13 @@ public void testSelfIntersectingPolygonClipped() { // Polygon with self crossing way // partly intersected by bbox polygon // happy if it works without crashing - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -887,7 +889,8 @@ public void testSelfIntersectingPolygonClipped() { @Test public void testMembersDisappear() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted List result = (new CellIterator( new OSHDBTimestamps( "2000-01-01T00:00:00Z", @@ -912,7 +915,7 @@ public void testMembersDisappear() { @Test public void testTimeIntervalAfterDeletionInVersion2() { - // relation in second version visible = false, timeinterval includes version 3 + // relation in second version visible = false, time interval includes version 3 List result = (new CellIterator( new OSHDBTimestamps( "2016-01-01T00:00:00Z", @@ -936,7 +939,7 @@ public void testTimeIntervalAfterDeletionInVersion2() { @Test public void testTimeIntervalAfterDeletionInCurrentVersion() { - // relation in first and third version visible = false, timeinterval includes version 3 + // relation in first and third version visible = false, time interval includes version 3 List result = (new CellIterator( new OSHDBTimestamps( "2016-01-01T00:00:00Z", @@ -960,7 +963,7 @@ public void testTimeIntervalAfterDeletionInCurrentVersion() { @Test public void testExcludingVersion2() { - // relation in second version visible = false, timeinterval includes version 3 + // relation in second version visible = false, time interval includes version 3 List result = (new CellIterator( new OSHDBTimestamps( "2012-01-01T00:00:00Z", @@ -969,7 +972,7 @@ public void testExcludingVersion2() { new OSHDBBoundingBox(-180,-90, 180, 90), areaDecider, oshEntity -> oshEntity.getId() == 500, - osmEntity -> !(osmEntity.getVersion()==2), + osmEntity -> !(osmEntity.getVersion() == 2), false )).iterateByContribution( oshdbDataGridCell @@ -985,14 +988,15 @@ public void testExcludingVersion2() { @Test public void testMembersDisappearClipped() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1023,14 +1027,14 @@ public void testMembersDisappearClipped() { @Test public void testTimeIntervalAfterDeletionInVersion2Clipped() { - // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation in second version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1057,14 +1061,14 @@ public void testTimeIntervalAfterDeletionInVersion2Clipped() { @Test public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { - // relation in first and third version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation in first and third version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1090,14 +1094,14 @@ public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { @Test public void testExcludingVersion2Clipped() { - // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + // relation in second version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1108,7 +1112,7 @@ public void testExcludingVersion2Clipped() { polygonFromCoordinates, areaDecider, oshEntity -> oshEntity.getId() == 500, - osmEntity -> !(osmEntity.getVersion()==2), + osmEntity -> !(osmEntity.getVersion() == 2), false )).iterateByContribution( oshdbDataGridCell @@ -1125,13 +1129,13 @@ public void testExcludingVersion2Clipped() { @Test public void testClippingPolygonIsVeryBig() { // relation with two way members(nodes of ways have changes in 2009 and 2011) - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1150,7 +1154,4 @@ public void testClippingPolygonIsVeryBig() { assertEquals(3, result.size()); } - - - } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java index 7476f67b0..f5719bd5b 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -19,11 +24,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionTypeNotMultipolygonTest { private GridOSHRelations oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -126,8 +126,7 @@ public void testWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -336,8 +335,7 @@ public void testNodesOfWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -598,13 +596,13 @@ public void testWaySplitUpInTwo() { @Test public void testPolygonIntersectingDataPartly() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -626,13 +624,13 @@ public void testPolygonIntersectingDataPartly() { @Test public void testPolygonIntersectingDataCompletely() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -654,13 +652,13 @@ public void testPolygonIntersectingDataCompletely() { @Test public void testPolygonNotIntersectingData() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(48,49); - coords[1]=new Coordinate(48 ,50); - coords[2]=new Coordinate(49,50); - coords[3]=new Coordinate(49,49); - coords[4]=new Coordinate(48,49); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(48,49); + coords[1] = new Coordinate(48,50); + coords[2] = new Coordinate(49,50); + coords[3] = new Coordinate(49,49); + coords[4] = new Coordinate(48,49); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -713,13 +711,13 @@ public void testNodeChangeOutsideBbox() { @Test public void testPolygonIntersectingDataCompletelyTimeIntervalAfterChanges() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -781,13 +779,13 @@ public void testBboxOutsidePolygon() { @Test public void testSelfIntersectingPolygonClipped() { // Polygon with self crossing way - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -810,7 +808,8 @@ public void testSelfIntersectingPolygonClipped() { @Test public void testMembersDisappear() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted List result = (new CellIterator( new OSHDBTimestamps( "2000-01-01T00:00:00Z", @@ -835,7 +834,7 @@ public void testMembersDisappear() { @Test public void testMembersDisappearAndPreviousIsNull() { // relation in last version without members, previous version visible=false - // timeinterval includes only last version + // time interval includes only last version List result = (new CellIterator( new OSHDBTimestamps( "2012-01-01T00:00:00Z", @@ -854,14 +853,14 @@ public void testMembersDisappearAndPreviousIsNull() { @Test public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { - // relation in first and third version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation in first and third version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java index d6142895b..f0e42297f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -17,10 +21,6 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionWaysTest { private GridOSHWays oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -548,7 +548,8 @@ public void testNodeRefsDeletedInVersion2() { assertEquals( EnumSet.of(ContributionType.CREATION), result.get(0).activities.get() - );assertEquals( + ); + assertEquals( EnumSet.of(ContributionType.GEOMETRY_CHANGE), result.get(1).activities.get() ); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java index 948c3a6e7..b2037e217 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -30,8 +32,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampNotOsmTypeSpecificTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; @@ -54,7 +54,8 @@ public IterateByTimestampNotOsmTypeSpecificTest() throws IOException { )); } - for (Entry> entry : osmXmlTestData.relations().asMap().entrySet()) { + for (Entry> entry : + osmXmlTestData.relations().asMap().entrySet()) { Collection relationVersions = entry.getValue(); oshRelations.add(OSHRelationImpl.build(new ArrayList<>(relationVersions), relationVersions.stream().flatMap(osmRelation -> @@ -74,14 +75,15 @@ public IterateByTimestampNotOsmTypeSpecificTest() throws IOException { @Test public void testCellOutsidePolygon() throws IOException { // GridOSHRelations cell-bbox is not covering query polygon - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,12.7); - coords[2]=new Coordinate(12.7,12.7); - coords[3]=new Coordinate(12.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + oshRelations); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,12.7); + coords[2] = new Coordinate(12.7,12.7); + coords[3] = new Coordinate(12.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -104,13 +106,14 @@ public void testCellOutsidePolygon() throws IOException { @Test public void testCellCoveringPolygon() throws IOException { // GridOSHRelations cell-bbox is completely covering query polygon - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(12.7,12.7); - coords[2]=new Coordinate(12.7,10.3); - coords[3]=new Coordinate(10.8,10.3); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, + oshRelations); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(12.7,12.7); + coords[2] = new Coordinate(12.7,10.3); + coords[3] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -133,14 +136,15 @@ public void testCellCoveringPolygon() throws IOException { @Test public void testCellFullyInsidePolygon() throws IOException { // GridOSHRelations cell-bbox is inside query polygon - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + oshRelations); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java index 28de62019..9c67c24a3 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -17,11 +22,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampsNodesTest { private GridOSHNodes oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -54,8 +54,10 @@ public void testGeometryChange() { ).collect(Collectors.toList()); assertEquals(11, result.size()); - assertNotEquals(result.get(1).geometry.get().getCoordinates(), result.get(0).geometry.get().getCoordinates()); - assertNotEquals(result.get(2).geometry.get().getCoordinates(), result.get(1).geometry.get().getCoordinates()); + assertNotEquals(result.get(1).geometry.get().getCoordinates(), + result.get(0).geometry.get().getCoordinates()); + assertNotEquals(result.get(2).geometry.get().getCoordinates(), + result.get(1).geometry.get().getCoordinates()); } @Test @@ -136,17 +138,28 @@ public void testMultipleChanges() { ).collect(Collectors.toList()); assertEquals(11, result.size()); - assertNotEquals(result.get(1).geometry.get().getCoordinates(), result.get(0).geometry.get().getCoordinates()); - assertArrayEquals(result.get(2).geometry.get().getCoordinates(), result.get(1).geometry.get().getCoordinates()); - assertNotEquals(result.get(3).geometry.get().getCoordinates(), result.get(2).geometry.get().getCoordinates()); - assertArrayEquals(result.get(5).geometry.get().getCoordinates(), result.get(3).geometry.get().getCoordinates()); - assertNotEquals(result.get(6).geometry.get().getCoordinates(), result.get(3).geometry.get().getCoordinates()); - assertArrayEquals(result.get(9).geometry.get().getCoordinates(), result.get(6).geometry.get().getCoordinates()); - assertNotEquals(result.get(1).osmEntity.getRawTags(), result.get(0).osmEntity.getRawTags()); - assertEquals(result.get(2).osmEntity.getRawTags(), result.get(1).osmEntity.getRawTags()); - assertNotEquals(result.get(3).osmEntity.getRawTags(), result.get(2).osmEntity.getRawTags()); - assertEquals(result.get(5).osmEntity.getRawTags(), result.get(4).osmEntity.getRawTags()); - assertNotEquals(result.get(9).osmEntity.getRawTags(), result.get(6).osmEntity.getRawTags()); + assertNotEquals(result.get(1).geometry.get().getCoordinates(), + result.get(0).geometry.get().getCoordinates()); + assertArrayEquals(result.get(2).geometry.get().getCoordinates(), + result.get(1).geometry.get().getCoordinates()); + assertNotEquals(result.get(3).geometry.get().getCoordinates(), + result.get(2).geometry.get().getCoordinates()); + assertArrayEquals(result.get(5).geometry.get().getCoordinates(), + result.get(3).geometry.get().getCoordinates()); + assertNotEquals(result.get(6).geometry.get().getCoordinates(), + result.get(3).geometry.get().getCoordinates()); + assertArrayEquals(result.get(9).geometry.get().getCoordinates(), + result.get(6).geometry.get().getCoordinates()); + assertNotEquals(result.get(1).osmEntity.getRawTags(), + result.get(0).osmEntity.getRawTags()); + assertEquals(result.get(2).osmEntity.getRawTags(), + result.get(1).osmEntity.getRawTags()); + assertNotEquals(result.get(3).osmEntity.getRawTags(), + result.get(2).osmEntity.getRawTags()); + assertEquals(result.get(5).osmEntity.getRawTags(), + result.get(4).osmEntity.getRawTags()); + assertNotEquals(result.get(9).osmEntity.getRawTags(), + result.get(6).osmEntity.getRawTags()); } @Test @@ -192,13 +205,13 @@ public void testTagChangeTagFilterWithoutSuccess() { @Test public void testTagFilterAndPolygonIntersectingDataPartly() { // lon lat changes, so that node in v2 is outside bbox - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -221,12 +234,12 @@ public void testTagFilterAndPolygonIntersectingDataPartly() { @Test public void testCoordinatesRelativeToPolygon() throws IOException { //different cases of relative position between node coordinate(s) and cell bbox / query polygon - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(0.0,0.0); - coords[1]=new Coordinate(1.5,0.0); - coords[2]=new Coordinate(0.0,1.5); - coords[3]=new Coordinate(0.0,0.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(0.0,0.0); + coords[1] = new Coordinate(1.5,0.0); + coords[2] = new Coordinate(0.0,1.5); + coords[3] = new Coordinate(0.0,0.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -241,7 +254,8 @@ public void testCoordinatesRelativeToPolygon() throws IOException { osmEntity -> true, false )).iterateByTimestamps( - GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)).getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/) + GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)) + .getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/) ).collect(Collectors.toList()); assertEquals(3, result.size()); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java index 4f351b5f3..34318c119 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -19,11 +24,6 @@ import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Polygon; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampsRelationsTest { private GridOSHRelations oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -106,8 +106,7 @@ public void testWaysNotExistent() { )).iterateByTimestamps( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -269,8 +268,7 @@ public void testNodesOfWaysNotExistent() { )).iterateByTimestamps( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -470,13 +468,13 @@ public void testWaySplitUpInTwo() { @Test public void testPolygonIntersectingDataPartly() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -500,13 +498,13 @@ public void testPolygonIntersectingDataPartly() { @Test public void testPolygonIntersectingDataOnlyAtBorderLine() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.7,10.4); - coords[1]=new Coordinate(10.94,10.4); - coords[2]=new Coordinate(10.94,10.9); - coords[3]=new Coordinate(10.7,10.9); - coords[4]=new Coordinate(10.7,10.4); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.7,10.4); + coords[1] = new Coordinate(10.94,10.4); + coords[2] = new Coordinate(10.94,10.9); + coords[3] = new Coordinate(10.7,10.9); + coords[4] = new Coordinate(10.7,10.4); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -529,13 +527,13 @@ public void testPolygonIntersectingDataOnlyAtBorderLine() { @Test public void testPolygonIntersectingDataCompletely() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -559,13 +557,13 @@ public void testPolygonIntersectingDataCompletely() { @Test public void testPolygonNotIntersectingData() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(48,49); - coords[1]=new Coordinate(48 ,50); - coords[2]=new Coordinate(49,50); - coords[3]=new Coordinate(49,49); - coords[4]=new Coordinate(48,49); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(48,49); + coords[1] = new Coordinate(48,50); + coords[2] = new Coordinate(49,50); + coords[3] = new Coordinate(49,49); + coords[4] = new Coordinate(48,49); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( @@ -612,13 +610,13 @@ public void testNodeChangeOutsideBbox() { @Test public void testPolygonIntersectingDataCompletelyTimeIntervalAfterChanges() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -715,13 +713,13 @@ public void testSelfIntersectingPolygonClipped() { // Polygon with self crossing way // partly intersected by bbox polygon // happy if it works without crashing - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -743,7 +741,8 @@ public void testSelfIntersectingPolygonClipped() { @Test public void testMembersDisappear() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted List result = (new CellIterator( new OSHDBTimestamps( "2000-01-01T00:00:00Z", @@ -805,14 +804,15 @@ public void testTimeIntervalAfterDeletionInCurrentVersion() { @Test public void testMembersDisappearClipped() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -836,13 +836,13 @@ public void testMembersDisappearClipped() { @Test public void testTimeIntervalAfterDeletionInVersion2Clipped() { // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -866,13 +866,13 @@ public void testTimeIntervalAfterDeletionInVersion2Clipped() { @Test public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { // relation in first and third version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -896,13 +896,13 @@ public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { @Test public void testExcludingVersion2Clipped() { // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -914,7 +914,7 @@ public void testExcludingVersion2Clipped() { polygonFromCoordinates, areaDecider, oshEntity -> oshEntity.getId() == 500, - osmEntity -> !(osmEntity.getVersion()==2), + osmEntity -> !(osmEntity.getVersion() == 2), false )).iterateByTimestamps( oshdbDataGridCell @@ -926,13 +926,13 @@ public void testExcludingVersion2Clipped() { @Test public void testClippingPolygonIsVeryBig() { // relation with two way members(nodes of ways have changes in 2009 and 2011) - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java index 8ffe810dc..541c91c13 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -17,10 +21,6 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampsWaysTest { private GridOSHWays oshdbDataGridCell; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java index b3e2951ab..9bff7263d 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java @@ -37,15 +37,8 @@ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader) throws IOE return getGridOSHNodes(osmXmlReader, -1, -1); } - public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader) throws IOException { - return getGridOSHWays(osmXmlReader, -1, -1); - } - - public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader) throws IOException { - return getGridOSHRelations(osmXmlReader, -1, -1); - } - - public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { + public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZoom, long cellId) + throws IOException { GridOSHNodes oshdbDataGridCellNodes; List oshNodes = new ArrayList<>(); for (Entry> entry : osmXmlReader.nodes().asMap().entrySet()) { @@ -57,7 +50,12 @@ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZo return oshdbDataGridCellNodes; } - public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { + public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader) throws IOException { + return getGridOSHWays(osmXmlReader, -1, -1); + } + + public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom, long cellId) + throws IOException { GridOSHWays oshdbDataGridCellWays; Map oshNodes = getOSHNodes(osmXmlReader); List oshWays = new ArrayList<>(); @@ -73,7 +71,12 @@ public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom return oshdbDataGridCellWays; } - public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { + public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader) throws IOException { + return getGridOSHRelations(osmXmlReader, -1, -1); + } + + public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader, int cellZoom, + long cellId) throws IOException { Map oshNodes = getOSHNodes(osmXmlReader); Map oshWays = getOSHWays(osmXmlReader); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java index b3ab49e2c..104db5c60 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.geometry; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; @@ -12,12 +14,10 @@ import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; - public class GeoTest { private final GeometryFactory gf = new GeometryFactory(); - private Coordinate[] constructCoordinates(double ...coordValues) { + private Coordinate[] constructCoordinates(double...coordValues) { Coordinate[] coords = new Coordinate[coordValues.length / 2]; for (int i = 0; i < coordValues.length / 2; i++) { coords[i] = new Coordinate(coordValues[i * 2], coordValues[i * 2 + 1]); @@ -25,7 +25,7 @@ private Coordinate[] constructCoordinates(double ...coordValues) { return coords; } - private LinearRing constructRing(double ...coordValues) { + private LinearRing constructRing(double...coordValues) { return gf.createLinearRing(constructCoordinates(coordValues)); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java index 801c63e36..20567c8bb 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; @@ -20,13 +23,10 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTest { private final OSMXmlReader testData = new OSMXmlReader(); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTest() { testData.add("./src/test/resources/geometryBuilder.osh"); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java index d03256f6d..ad04664c0 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java @@ -1,11 +1,13 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.fip; -import org.locationtech.jts.geom.*; +import static org.junit.Assert.assertEquals; + import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; public class FastBboxInPolygonTest { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java index 4c3c1858c..8b834e531 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java @@ -2,10 +2,10 @@ import static org.junit.Assert.assertEquals; -import org.locationtech.jts.geom.MultiPolygon; -import org.locationtech.jts.geom.Polygon; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.junit.Test; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; public class FastBboxOutsidePolygonTest { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java index 90cf4bb61..ca42108ea 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java @@ -2,8 +2,12 @@ import static org.junit.Assert.assertEquals; -import org.locationtech.jts.geom.*; import org.junit.Test; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LinearRing; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; public class FastPointInPolygonTest { @@ -11,18 +15,18 @@ public class FastPointInPolygonTest { * @return a reversed "Σ"-shaped concave polygon */ public static Polygon createPolygon() { - GeometryFactory gf = new GeometryFactory(); + final GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[100]; coordinates[0] = new Coordinate(0,0); coordinates[1] = new Coordinate(1,1); coordinates[2] = new Coordinate(-1,1); - for (int i=3; i<=96; i++) { - coordinates[i] = new Coordinate(-1.0, 1.0 - 2.0*(i-2)/95); + for (int i = 3; i <= 96; i++) { + coordinates[i] = new Coordinate(-1.0, 1.0 - 2.0 * (i - 2) / 95); } coordinates[97] = new Coordinate(-1,-1); coordinates[98] = new Coordinate(1,-1); coordinates[99] = new Coordinate(0,0); - LinearRing linear = new GeometryFactory().createLinearRing(coordinates); + LinearRing linear = gf.createLinearRing(coordinates); return new Polygon(linear, null, gf); } @@ -30,21 +34,21 @@ public static Polygon createPolygon() { * @return a square with a central square hole */ public static Polygon createPolygonWithHole() { - GeometryFactory gf = new GeometryFactory(); + final GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates1 = new Coordinate[5]; coordinates1[0] = new Coordinate(4,-1); coordinates1[1] = new Coordinate(4,1); coordinates1[2] = new Coordinate(2,1); coordinates1[3] = new Coordinate(2,-1); coordinates1[4] = new Coordinate(4,-1); - LinearRing linear1 = new GeometryFactory().createLinearRing(coordinates1); + final LinearRing linear1 = gf.createLinearRing(coordinates1); Coordinate[] coordinates2 = new Coordinate[5]; coordinates2[0] = new Coordinate(3.5,-0.5); coordinates2[1] = new Coordinate(3.5,0.5); coordinates2[2] = new Coordinate(2.5,0.5); coordinates2[3] = new Coordinate(2.5,-0.5); coordinates2[4] = new Coordinate(3.5,-0.5); - LinearRing linear2 = new GeometryFactory().createLinearRing(coordinates2); + final LinearRing linear2 = gf.createLinearRing(coordinates2); return new Polygon(linear1, new LinearRing[] { linear2 }, gf); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java index aaa29430d..c03d077b5 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java @@ -3,14 +3,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; -import org.locationtech.jts.geom.GeometryCollection; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import org.junit.Test; import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; @@ -40,11 +38,36 @@ public void testNullGeometryPolygon() { public void testBug206() throws ParseException { // see https://github.com/GIScience/oshdb/pull/204 - String polyWkt = "POLYGON ((-0.0473915 51.5539955,-0.0473872 51.5540543,-0.0473811 51.554121,-0.0473792 51.5541494,-0.0473193 51.5541485,-0.047305 51.5540903,-0.0472924 51.5540904,-0.0472852 51.5540674,-0.0472735 51.5540681,-0.0472692 51.5540517,-0.0472852 51.5540499,-0.0472602 51.5539917,-0.0472317 51.553925,-0.0472157 51.5539254,-0.0472097 51.5539106,-0.0473992 51.5538913,-0.0474735 51.5538845,-0.0475498 51.5538774,-0.0476179 51.5538712,-0.0476923 51.5538643,-0.0476923 51.5538575,-0.0477741 51.5538544,-0.0478501 51.5538516,-0.0479217 51.553849,-0.0479986 51.5538462,-0.0480796 51.5538432,-0.0481503 51.5538406,-0.0482264 51.5538378,-0.0482708 51.5538377,-0.0483561 51.5538358,-0.0484275 51.5538343,-0.0485046 51.5538325,-0.0485294 51.553832,-0.0485255 51.5539171,-0.0485813 51.5539157,-0.0485787 51.5539268,-0.0485505 51.5540481,-0.048532 51.5540479,-0.0485309 51.5539901,-0.0484762 51.5539897,-0.0484784 51.5540545,-0.0484507 51.5540541,-0.0484187 51.5540536,-0.0484198 51.5539893,-0.0483923 51.5539892,-0.0483925 51.5539796,-0.0483729 51.5539795,-0.048362 51.5539794,-0.0483618 51.553989,-0.0483251 51.5539888,-0.0483241 51.5540522,-0.0482959 51.5540518,-0.0482676 51.5540514,-0.0482697 51.5539916,-0.0482366 51.5539911,-0.0482369 51.5539847,-0.0482236 51.5539846,-0.0482067 51.5539843,-0.0482064 51.5539907,-0.0481825 51.5539904,-0.0481803 51.5540561,-0.0481466 51.5540562,-0.0481136 51.5540562,-0.048115 51.5539953,-0.0480721 51.5539945,-0.048072 51.5540025,-0.0480546 51.5540021,-0.0480539 51.5540142,-0.0480194 51.5540138,-0.048018 51.5540561,-0.04799 51.5540558,-0.0479623 51.5540556,-0.047964 51.5540149,-0.0479185 51.5540142,-0.0478768 51.5540135,-0.047875 51.5540547,-0.0478614 51.5540546,-0.0478616 51.5540458,-0.0478423 51.5540457,-0.0478439 51.554006,-0.0477667 51.5540059,-0.0476868 51.5540057,-0.0476872 51.5539952,-0.047616 51.5539953,-0.0475449 51.5539954,-0.0474682 51.5539954,-0.0473915 51.5539955))"; + String polyWkt = "POLYGON ((-0.0473915 51.5539955,-0.0473872 51.5540543,-0.0473811 51.554121," + + "-0.0473792 51.5541494,-0.0473193 51.5541485,-0.047305 51.5540903,-0.0472924 51.5540904," + + "-0.0472852 51.5540674,-0.0472735 51.5540681,-0.0472692 51.5540517,-0.0472852 51.5540499," + + "-0.0472602 51.5539917,-0.0472317 51.553925,-0.0472157 51.5539254,-0.0472097 51.5539106," + + "-0.0473992 51.5538913,-0.0474735 51.5538845,-0.0475498 51.5538774,-0.0476179 51.5538712," + + "-0.0476923 51.5538643,-0.0476923 51.5538575,-0.0477741 51.5538544,-0.0478501 51.5538516," + + "-0.0479217 51.553849,-0.0479986 51.5538462,-0.0480796 51.5538432,-0.0481503 51.5538406," + + "-0.0482264 51.5538378,-0.0482708 51.5538377,-0.0483561 51.5538358,-0.0484275 51.5538343," + + "-0.0485046 51.5538325,-0.0485294 51.553832,-0.0485255 51.5539171,-0.0485813 51.5539157," + + "-0.0485787 51.5539268,-0.0485505 51.5540481,-0.048532 51.5540479,-0.0485309 51.5539901," + + "-0.0484762 51.5539897,-0.0484784 51.5540545,-0.0484507 51.5540541,-0.0484187 51.5540536," + + "-0.0484198 51.5539893,-0.0483923 51.5539892,-0.0483925 51.5539796,-0.0483729 51.5539795," + + "-0.048362 51.5539794,-0.0483618 51.553989,-0.0483251 51.5539888,-0.0483241 51.5540522," + + "-0.0482959 51.5540518,-0.0482676 51.5540514,-0.0482697 51.5539916,-0.0482366 51.5539911," + + "-0.0482369 51.5539847,-0.0482236 51.5539846,-0.0482067 51.5539843,-0.0482064 51.5539907," + + "-0.0481825 51.5539904,-0.0481803 51.5540561,-0.0481466 51.5540562,-0.0481136 51.5540562," + + "-0.048115 51.5539953,-0.0480721 51.5539945,-0.048072 51.5540025,-0.0480546 51.5540021," + + "-0.0480539 51.5540142,-0.0480194 51.5540138,-0.048018 51.5540561,-0.04799 51.5540558," + + "-0.0479623 51.5540556,-0.047964 51.5540149,-0.0479185 51.5540142,-0.0478768 51.5540135," + + "-0.047875 51.5540547,-0.0478614 51.5540546,-0.0478616 51.5540458,-0.0478423 51.5540457," + + "-0.0478439 51.554006,-0.0477667 51.5540059,-0.0476868 51.5540057,-0.0476872 51.5539952," + + "-0.047616 51.5539953,-0.0475449 51.5539954,-0.0474682 51.5539954,-0.0473915 51.5539955)" + + ")"; Polygon poly = (Polygon) (new WKTReader()).read(polyWkt); FastPolygonOperations pop = new FastPolygonOperations(poly); - String testWkt = "POLYGON ((-0.0478421 51.5540544,-0.0478399 51.5541248,-0.0478499 51.5541249,-0.0478549 51.5541307,-0.0478795 51.5541313,-0.0478858 51.5541252,-0.0479136 51.5541254,-0.0479185 51.5540142,-0.0478768 51.5540135,-0.047875 51.5540547,-0.0478614 51.5540546,-0.0478616 51.5540458,-0.0478423 51.5540457,-0.0478421 51.5540544))"; + String testWkt = "POLYGON ((-0.0478421 51.5540544,-0.0478399 51.5541248,-0.0478499 51.5541249," + + "-0.0478549 51.5541307,-0.0478795 51.5541313,-0.0478858 51.5541252,-0.0479136 51.5541254," + + "-0.0479185 51.5540142,-0.0478768 51.5540135,-0.047875 51.5540547,-0.0478614 51.5540546," + + "-0.0478616 51.5540458,-0.0478423 51.5540457,-0.0478421 51.5540544))"; Geometry test = (new WKTReader()).read(testWkt); assertNotNull(pop.intersection(test)); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java index 9aadb184c..b5f616e44 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java @@ -7,15 +7,32 @@ public abstract class FakeTagInterpreter implements TagInterpreter { @Override - public boolean isArea(OSMEntity entity) { return false; } + public boolean isArea(OSMEntity entity) { + return false; + } + @Override - public boolean isLine(OSMEntity entity) { return false; } + public boolean isLine(OSMEntity entity) { + return false; + } + @Override - public boolean hasInterestingTagKey(OSMEntity osm) { return false; } + public boolean hasInterestingTagKey(OSMEntity osm) { + return false; + } + @Override - public boolean isMultipolygonOuterMember(OSMMember osmMember) { return false; } + public boolean isMultipolygonOuterMember(OSMMember osmMember) { + return false; + } + @Override - public boolean isMultipolygonInnerMember(OSMMember osmMember) { return false; } + public boolean isMultipolygonInnerMember(OSMMember osmMember) { + return false; + } + @Override - public boolean isOldStyleMultipolygon(OSMRelation osmRelation) { return false; } + public boolean isOldStyleMultipolygon(OSMRelation osmRelation) { + return false; + } } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java index 928d200c8..1bc8a90c7 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java @@ -21,7 +21,8 @@ public OSMXmlReaderTagInterpreter(OSMXmlReader osmXmlReader) { area = osmXmlReader.keys().getOrDefault("area", -1); areaYes = area == -1 ? -1 : osmXmlReader.keyValues().get(area).getOrDefault("yes", -1); type = osmXmlReader.keys().getOrDefault("type", -1); - typeMultipolygon = type == -1 ? -1 : osmXmlReader.keyValues().get(type).getOrDefault("multipolygon", -1); + typeMultipolygon = type == -1 ? -1 : osmXmlReader.keyValues().get(type) + .getOrDefault("multipolygon", -1); emptyRole = osmXmlReader.roles().getOrDefault("", -1); outer = osmXmlReader.roles().getOrDefault("outer", -1); inner = osmXmlReader.roles().getOrDefault("inner", -1); @@ -31,8 +32,8 @@ public OSMXmlReaderTagInterpreter(OSMXmlReader osmXmlReader) { public boolean isArea(OSMEntity e) { if (e instanceof OSMWay) { OSMMember[] nds = ((OSMWay) e).getRefs(); - return nds.length >= 4 && nds[0].getId() == nds[nds.length - 1].getId() && - e.hasTagValue(area, areaYes); + return nds.length >= 4 && nds[0].getId() == nds[nds.length - 1].getId() + && e.hasTagValue(area, areaYes); } if (e instanceof OSMRelation) { return e.hasTagValue(type, typeMultipolygon); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java index c167462ba..778fda7ad 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.incomplete; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -13,16 +17,12 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestPolygonIncompleteDataTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestPolygonIncompleteDataTest() { testData.add("./src/test/resources/incomplete-osm/polygon.osm"); @@ -62,7 +62,8 @@ public void testWayNotExistent() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.31 1.04, 7.33 1.05, 7.33 1.04, 7.32 1.04, 7.31 1.01,7.31 1.01,7.31 1.04)))" + "MULTIPOLYGON(((7.31 1.04, 7.33 1.05, 7.33 1.04, 7.32 1.04, 7.31 1.01,7.31 1.01," + + "7.31 1.04)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -75,8 +76,7 @@ public void testAllNodesOfWayNotExistent() { Geometry result1 = null; try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java index dc38561bd..2e33b2abe 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.incomplete; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -11,15 +14,12 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.LineString; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestWayIncompleteDataTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestWayIncompleteDataTest() { testData.add("./src/test/resources/incomplete-osm/way.osm"); @@ -34,8 +34,7 @@ public void testOneOfNodesNotExistent() { Geometry result1 = null; try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -51,8 +50,7 @@ public void testWayAreaYes() { Geometry result1 = null; try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -69,8 +67,7 @@ public void testAllNodesNotExistent() { try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); assertTrue(result1.getCoordinates().length == 0); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java index 134ee5ab5..85f13f45e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -11,13 +14,10 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Point; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest() { testData.add("./src/test/resources/different-timestamps/node.osm"); @@ -50,11 +50,11 @@ public void testGeometryChange() { assertEquals(1.425, ((Point) result3).getX(), DELTA); assertEquals(1.23, ((Point) result3).getY(), DELTA); // timestamp after newest timestamp - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity3, timestamp_after, areaDecider); - assertTrue(result_after instanceof Point); - assertEquals(1.425, ((Point) result_after).getX(), DELTA); - assertEquals(1.23, ((Point) result_after).getY(), DELTA); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entity3, timestampAfter, areaDecider); + assertTrue(resultAfter instanceof Point); + assertEquals(1.425, ((Point) resultAfter).getX(), DELTA); + assertEquals(1.23, ((Point) resultAfter).getY(), DELTA); } @Test(expected = AssertionError.class) @@ -62,8 +62,8 @@ public void testInvalidAccess() { // A single node, lat lon changed over time OSMEntity entity = testData.nodes().get(1L).get(0); // timestamp before oldest timestamp - OSHDBTimestamp timestamp_before = TimestampParser.toOSHDBTimestamp("2007-01-01T00:00:00Z"); - Geometry result_before = OSHDBGeometryBuilder.getGeometry(entity, timestamp_before, areaDecider); + OSHDBTimestamp timestampBefore = TimestampParser.toOSHDBTimestamp("2007-01-01T00:00:00Z"); + Geometry resultBefore = OSHDBGeometryBuilder.getGeometry(entity, timestampBefore, areaDecider); } @Test diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java index 50f7060ea..684303a4e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -16,14 +20,10 @@ import org.locationtech.jts.geom.Polygonal; import org.locationtech.jts.io.ParseException; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest() { testData.add("./src/test/resources/different-timestamps/type-not-multipolygon.osm"); @@ -39,8 +39,7 @@ public void testGeometryChange() throws ParseException { Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertTrue(result instanceof GeometryCollection); assertTrue(result.isValid()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -51,8 +50,7 @@ public void testGeometryChange() throws ParseException { Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); assertTrue(result1 instanceof GeometryCollection); assertTrue(result1.isValid()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -63,8 +61,7 @@ public void testGeometryChange() throws ParseException { Geometry result2 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp2, areaDecider); assertTrue(result2 instanceof GeometryCollection || result2 instanceof Polygonal); assertTrue(result2.getNumGeometries() == 3); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -82,8 +79,7 @@ public void testVisibleChange() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -93,8 +89,7 @@ public void testVisibleChange() throws ParseException { try { Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); assertTrue(result1.isEmpty()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -108,8 +103,7 @@ public void testVisibleChange() throws ParseException { assertTrue(result2.getNumGeometries() == 2); assertTrue(result2.getGeometryN(0) instanceof LineString); assertTrue(result2.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -126,8 +120,7 @@ public void testWaysNotExistent() { assertTrue(result instanceof GeometryCollection); assertTrue(result.isValid()); assertTrue(result.isEmpty()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -144,8 +137,7 @@ public void testTagChange() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -158,8 +150,7 @@ public void testTagChange() throws ParseException { assertTrue(result1.isValid()); assertTrue(result1.getNumGeometries() == 1); assertTrue(result1.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -172,8 +163,7 @@ public void testTagChange() throws ParseException { assertTrue(result2.isValid()); assertTrue(result2.getNumGeometries() == 1); assertTrue(result2.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -191,8 +181,7 @@ public void testGeometryChangeOfNodeRefsInWays() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -206,24 +195,22 @@ public void testGeometryChangeOfNodeRefsInWays() throws ParseException { assertTrue(result1.getNumGeometries() == 2); assertTrue(result1.getGeometryN(0) instanceof LineString); assertTrue(result1.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version in between - OSMEntity entity_between = testData.relations().get(504L).get(0); - OSHDBTimestamp timestamp_between = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + OSMEntity entityBetween = testData.relations().get(504L).get(0); + OSHDBTimestamp timestampBetween = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); try { - Geometry result_between = OSHDBGeometryBuilder - .getGeometry(entity_between, timestamp_between, areaDecider); - assertTrue(result_between instanceof GeometryCollection); - assertTrue(result_between.isValid()); - assertTrue(result_between.getNumGeometries() == 2); - assertTrue(result_between.getGeometryN(0) instanceof LineString); - assertTrue(result_between.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + Geometry resultBetween = OSHDBGeometryBuilder + .getGeometry(entityBetween, timestampBetween, areaDecider); + assertTrue(resultBetween instanceof GeometryCollection); + assertTrue(resultBetween.isValid()); + assertTrue(resultBetween.getNumGeometries() == 2); + assertTrue(resultBetween.getGeometryN(0) instanceof LineString); + assertTrue(resultBetween.getGeometryN(1) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -240,23 +227,21 @@ public void testGeometryChangeOfNodeCoordinatesInWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(505L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(505L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder - .getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 1); - assertTrue(result_after.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + Geometry resultAfter = OSHDBGeometryBuilder + .getGeometry(entityAfter, timestampAfter, areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 1); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -275,24 +260,23 @@ public void testGeometryChangeOfNodeCoordinatesInRelationAndWay() throws ParseEx assertTrue(result.getGeometryN(0) instanceof Point); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(506L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(506L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 3); - assertTrue(result_after.getGeometryN(0) instanceof Point); - assertTrue(result_after.getGeometryN(1) instanceof Point); - assertTrue(result_after.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 3); + assertTrue(resultAfter.getGeometryN(0) instanceof Point); + assertTrue(resultAfter.getGeometryN(1) instanceof Point); + assertTrue(resultAfter.getGeometryN(2) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -308,8 +292,7 @@ public void testGeometryCollection() { assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 6); assertFalse(result instanceof MultiPolygon); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -325,8 +308,7 @@ public void testNodesOfWaysNotExistent() { result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertTrue(result instanceof GeometryCollection); assertTrue(result.isValid()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -344,23 +326,22 @@ public void testVisibleChangeOfNodeInWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(509L).get(0); + OSMEntity entityAfter = testData.relations().get(509L).get(0); // timestamp where node 52 visible is true - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 1); - assertTrue(result_after.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 1); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -377,23 +358,21 @@ public void testTagChangeOfNodeInWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(510L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(510L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder - .getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 1); - assertTrue(result_after.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + Geometry resultAfter = OSHDBGeometryBuilder + .getGeometry(entityAfter, timestampAfter, areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 1); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -410,20 +389,19 @@ public void testVisibleChangeOfWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after, visible false - OSMEntity entity_after = testData.relations().get(511L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(511L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isEmpty()); - } - catch (Exception e) { + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isEmpty()); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -441,22 +419,21 @@ public void testVisibleChangeOfOneWayOfOuterRing() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after: way 120 does not exit any more - OSMEntity entity_after = testData.relations().get(512L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(512L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.getNumGeometries() == 2); - assertTrue(result_after.getGeometryN(0) instanceof LineString - || result_after.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.getNumGeometries() == 2); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString + || resultAfter.getGeometryN(1) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -473,8 +450,7 @@ public void testTagChangeOfWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -487,8 +463,7 @@ public void testTagChangeOfWay() throws ParseException { assertTrue(result1.isValid()); assertTrue(result1.getNumGeometries() == 1); assertTrue(result1.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -501,8 +476,7 @@ public void testTagChangeOfWay() throws ParseException { assertTrue(result2.isValid()); assertTrue(result2.getNumGeometries() == 1); assertTrue(result2.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -520,10 +494,9 @@ public void testOneOfTwoPolygonDisappears() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ - e.printStackTrace(); - fail("Should not have thrown any exception"); + } catch (Exception e) { + e.printStackTrace(); + fail("Should not have thrown any exception"); } // second version OSMEntity entity1 = testData.relations().get(514L).get(1); @@ -534,8 +507,7 @@ public void testOneOfTwoPolygonDisappears() throws ParseException { assertTrue(result1.isValid()); assertTrue(result1.getNumGeometries() == 1); assertTrue(result1.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -552,11 +524,10 @@ public void testWaySplitUpInTwo() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); - } + } // second version OSMEntity entity1 = testData.relations().get(515L).get(1); OSHDBTimestamp timestamp1 = entity1.getTimestamp(); @@ -567,8 +538,7 @@ public void testWaySplitUpInTwo() throws ParseException { assertTrue(result1.getNumGeometries() == 2); assertTrue(result1.getGeometryN(0) instanceof LineString); assertTrue(result1.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -581,13 +551,12 @@ public void testRestrictionRoles() { OSHDBTimestamp timestamp1 = entity1.getTimestamp(); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -600,12 +569,11 @@ public void testRolesArePartAndOutline() { OSHDBTimestamp timestamp1 = entity1.getTimestamp(); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -614,13 +582,12 @@ public void testRolesArePartAndOutline() { OSHDBTimestamp timestamp2 = entity2.getTimestamp(); try { Geometry result2 = OSHDBGeometryBuilder.getGeometry(entity2, timestamp2, areaDecider); - assertTrue(result2 instanceof GeometryCollection ); + assertTrue(result2 instanceof GeometryCollection); assertTrue(result2.getNumGeometries() == 3); assertTrue(result2.getGeometryN(0) instanceof LineString); assertTrue(result2.getGeometryN(1) instanceof LineString); assertTrue(result2.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java index 2fe4c1e23..3861a4a71 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java @@ -1,8 +1,12 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.osm.OSMRelation; -import org.heigit.bigspatialdata.oshdb.osm.OSMWay; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; import org.heigit.bigspatialdata.oshdb.util.geometry.helpers.OSMXmlReaderTagInterpreter; @@ -18,16 +22,11 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest() { testData.add("./src/test/resources/different-timestamps/polygon.osm"); @@ -70,8 +69,7 @@ public void testGeometryChange() throws ParseException { Geometry result2 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp2, areaDecider); assertTrue(result2 instanceof GeometryCollection || result2 instanceof Polygonal); assertTrue(result2.getNumGeometries() == 3); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -120,8 +118,7 @@ public void testWaysNotExistent() { try { OSHDBTimestamp timestamp = entity.getTimestamp(); result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -196,18 +193,19 @@ public void testGeometryChangeOfNodeRefsInWays() throws ParseException { Geometry intersection1 = result1.intersection(expectedPolygon1); assertEquals(expectedPolygon1.getArea(), intersection1.getArea(), DELTA); // version in between - OSMEntity entity_between = testData.relations().get(504L).get(0); - OSHDBTimestamp timestamp_between = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); - Geometry result_between = OSHDBGeometryBuilder.getGeometry(entity_between, timestamp_between, areaDecider); - assertTrue(result_between instanceof Polygon); - assertTrue(result_between.isValid()); - assertEquals(10, result_between.getCoordinates().length); - Geometry expectedPolygon_between = (new WKTReader()).read( + OSMEntity entityBetween = testData.relations().get(504L).get(0); + OSHDBTimestamp timestampBetween = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + Geometry resultBetween = OSHDBGeometryBuilder.getGeometry(entityBetween, timestampBetween, + areaDecider); + assertTrue(resultBetween instanceof Polygon); + assertTrue(resultBetween.isValid()); + assertEquals(10, resultBetween.getCoordinates().length); + Geometry expectedPolygonBetween = (new WKTReader()).read( "MULTIPOLYGON(((7.24 1.04, 7.24 1.07, 7.31 1.07, 7.31 1.04 , 7.24 1.04)," + "(7.26 1.055, 7.265 1.06, 7.28 1.06,7.265 1.065, 7.26 1.055)))" ); - Geometry intersection_between = result_between.intersection(expectedPolygon_between); - assertEquals(expectedPolygon_between.getArea(), intersection_between.getArea(), DELTA); + Geometry intersectionBetween = resultBetween.intersection(expectedPolygonBetween); + assertEquals(expectedPolygonBetween.getArea(), intersectionBetween.getArea(), DELTA); } @Test @@ -225,17 +223,18 @@ public void testGeometryChangeOfNodeCoordinatesInWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(505L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(5, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSMEntity entityAfter = testData.relations().get(505L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(5, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.24 1.042, 7.242 1.07, 7.305 1.07, 7.295 1.039 , 7.24 1.042)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -253,17 +252,18 @@ public void testGeometryChangeOfNodeCoordinatesInRelationAndWay() throws ParseEx Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(506L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(4, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSMEntity entityAfter = testData.relations().get(506L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(4, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.24 1.042, 7.242 1.07, 7.295 1.039 , 7.24 1.042)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -277,8 +277,7 @@ public void testGeometryCollection() { assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 6); assertFalse(result instanceof MultiPolygon); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -292,8 +291,7 @@ public void testNodesOfWaysNotExistent() { try { OSHDBTimestamp timestamp = entity.getTimestamp(); result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -315,18 +313,19 @@ public void testVisibleChangeOfNodeInWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(509L).get(0); + OSMEntity entityAfter = testData.relations().get(509L).get(0); // timestamp where node 52 visible is true - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(5, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(5, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.303 1.042, 7.31 1.06, 7.32 1.07, 7.32 1.04, 7.303 1.042)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -344,17 +343,18 @@ public void testTagChangeOfNodeInWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(510L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(4, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSMEntity entityAfter = testData.relations().get(510L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(4, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.295 1.039, 1.43 1.24, 7.32 1.04, 7.295 1.039)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -372,10 +372,11 @@ public void testVisibleChangeOfWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after, visible false - OSMEntity entity_after = testData.relations().get(511L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after.isEmpty()); + OSMEntity entityAfter = testData.relations().get(511L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter.isEmpty()); } @Test @@ -393,11 +394,12 @@ public void testVisibleChangeOfOneWayOfOuterRing() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after: way 120 does not exit any more - OSMEntity entity_after = testData.relations().get(512L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.getNumGeometries() == 2); + OSMEntity entityAfter = testData.relations().get(512L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.getNumGeometries() == 2); } @Test diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java index 4af195c89..af87e9244 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.osm.OSMWay; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; @@ -14,13 +17,10 @@ import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.io.ParseException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest() { testData.add("./src/test/resources/different-timestamps/way.osm"); @@ -91,10 +91,11 @@ public void testGeometryChange() throws ParseException { assertEquals(1.43, (((LineString) result3).getCoordinateN(8)).x, DELTA); assertEquals(1.31, (((LineString) result3).getCoordinateN(8)).y, DELTA); // timestamp after last one - OSMEntity entity_after = testData.ways().get(100L).get(2); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof LineString); + OSMEntity entityAfter = testData.ways().get(100L).get(2); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof LineString); assertEquals(1.42, (((LineString) result3).getCoordinateN(0)).x, DELTA); assertEquals(1.22, (((LineString) result3).getCoordinateN(0)).y, DELTA); assertEquals(1.42, (((LineString) result3).getCoordinateN(1)).x, DELTA); @@ -141,15 +142,16 @@ public void testGeometryChangeOfNodeInWay() throws ParseException { assertEquals(1.43, (((LineString) result2).getCoordinateN(2)).x, DELTA); assertEquals(1.30, (((LineString) result2).getCoordinateN(2)).y, DELTA); // timestamp in between - OSHDBTimestamp timestamp_between = TimestampParser.toOSHDBTimestamp("2009-02-01T00:00:00Z"); - OSMEntity entity_between = testData.ways().get(101L).get(0); - Geometry result_between = OSHDBGeometryBuilder.getGeometry(entity_between, timestamp_between, areaDecider); - assertTrue(result_between instanceof LineString); - assertEquals(2,result_between.getNumPoints()); - assertEquals(1.42, (((LineString) result_between).getCoordinateN(0)).x, DELTA); - assertEquals(1.225, (((LineString) result_between).getCoordinateN(0)).y, DELTA); - assertEquals(1.445, (((LineString) result_between).getCoordinateN(1)).x, DELTA); - assertEquals(1.225, (((LineString) result_between).getCoordinateN(1)).y, DELTA); + OSHDBTimestamp timestampBetween = TimestampParser.toOSHDBTimestamp("2009-02-01T00:00:00Z"); + OSMEntity entityBetween = testData.ways().get(101L).get(0); + Geometry resultBetween = OSHDBGeometryBuilder.getGeometry(entityBetween, timestampBetween, + areaDecider); + assertTrue(resultBetween instanceof LineString); + assertEquals(2,resultBetween.getNumPoints()); + assertEquals(1.42, (((LineString) resultBetween).getCoordinateN(0)).x, DELTA); + assertEquals(1.225, (((LineString) resultBetween).getCoordinateN(0)).y, DELTA); + assertEquals(1.445, (((LineString) resultBetween).getCoordinateN(1)).x, DELTA); + assertEquals(1.225, (((LineString) resultBetween).getCoordinateN(1)).y, DELTA); } @Test @@ -239,6 +241,7 @@ public void testMultipleChangesOnNodesAndWays() throws ParseException { assertEquals(4, result4.getNumPoints()); } + // MULTIPOLYGON(((1.45 1.45,1.46 1.45,1.46 1.44,1.45 1.44))) @Test public void testPolygonAreaYesTagDisappears() throws ParseException { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java index c2f9f6400..8c7657884 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java @@ -1,5 +1,11 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmtestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -15,18 +21,12 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmTestData1xxTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmTestData1xxTest() { testData.add("./src/test/resources/osm-testdata/all.osm"); @@ -86,7 +86,7 @@ public void test112() { assertTrue(result1 instanceof LineString); assertEquals(5, result1.getCoordinates().length); assertEquals( - ((LineString) result1).getCoordinateN(result1.getNumPoints()-1), + ((LineString) result1).getCoordinateN(result1.getNumPoints() - 1), ((LineString) result1).getCoordinateN(0) ); } @@ -114,7 +114,7 @@ public void test114() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertEquals( - ((LineString) result1).getCoordinateN(result1.getNumPoints()-1), + ((LineString) result1).getCoordinateN(result1.getNumPoints() - 1), ((LineString) result2).getCoordinateN(0) ); } @@ -129,8 +129,8 @@ public void test115() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertEquals( - ((LineString) result1).getCoordinateN(result1.getNumPoints()-1), - ((LineString) result2).getCoordinateN(result2.getNumPoints()-1) + ((LineString) result1).getCoordinateN(result1.getNumPoints() - 1), + ((LineString) result2).getCoordinateN(result2.getNumPoints() - 1) ); } @@ -150,15 +150,15 @@ public void test116() { int idx2 = result2.getNumPoints(); int idx3 = result3.getNumPoints(); assertEquals( - ((LineString) result3).getCoordinateN(idx3-1), + ((LineString) result3).getCoordinateN(idx3 - 1), ((LineString) result1).getCoordinateN(0) ); assertEquals( - ((LineString) result1).getCoordinateN(idx1-1), + ((LineString) result1).getCoordinateN(idx1 - 1), ((LineString) result2).getCoordinateN(0) ); assertEquals( - ((LineString) result2).getCoordinateN(idx2-1), + ((LineString) result2).getCoordinateN(idx2 - 1), ((LineString) result3).getCoordinateN(0) ); } @@ -169,8 +169,7 @@ public void test120() { OSMEntity entity1 = testData.ways().get(120800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -182,8 +181,7 @@ public void test121() { OSMEntity entity1 = testData.ways().get(121800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -195,8 +193,7 @@ public void test122() { OSMEntity entity1 = testData.ways().get(122800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -208,8 +205,7 @@ public void test123() { OSMEntity entity1 = testData.ways().get(123800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -221,8 +217,7 @@ public void test124() { OSMEntity entity1 = testData.ways().get(124800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -238,8 +233,8 @@ public void test130() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertTrue(result1.crosses(result2)); - for (int j = 0; j< result1.getLength();j++){ - for (int i = 0; i< result2.getLength();i++) { + for (int j = 0; j < result1.getLength();j++) { + for (int i = 0; i < result2.getLength();i++) { assertNotEquals(((LineString) result1).getCoordinateN(j), ((LineString) result2).getCoordinateN(i)); } @@ -256,13 +251,11 @@ public void test131() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertTrue(result1.intersects(result2)); - for (int j = 0; j< result1.getLength();j++){ - for (int i = 0; i< result2.getLength();i++) { + for (int j = 0; j < result1.getLength();j++) { + for (int i = 0; i < result2.getLength();i++) { try { - ((LineString) result1).getCoordinateN(j).equals( - ((LineString) result2).getCoordinateN(i)); - } - catch(Exception e){ + ((LineString) result1).getCoordinateN(j).equals(((LineString) result2).getCoordinateN(i)); + } catch (Exception e) { e.printStackTrace(); fail("No common node"); } @@ -281,13 +274,12 @@ public void test132() { assertTrue(result2 instanceof LineString); assertTrue(result1.crosses(result2)); assertTrue(result1.intersects(result2)); - for (int j = 0; j< result1.getLength();j++){ - for (int i = 0; i< result2.getLength();i++) { + for (int j = 0; j < result1.getLength();j++) { + for (int i = 0; i < result2.getLength();i++) { try { ((LineString) result1).getCoordinateN(j).equals( ((LineString) result2).getCoordinateN(i)); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("No common node"); } @@ -301,9 +293,10 @@ public void test133() { OSMEntity entity1 = testData.ways().get(133800L).get(0); Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); assertTrue(result1 instanceof LineString); - // If a LineString intersects like that, isSimple() will return false as self-intersection is not allowed for Simple Geometries. + // If a LineString intersects like that, isSimple() will return false as self-intersection is + // not allowed for Simple Geometries. assertFalse(result1.isSimple()); - // punkt mit punkt, linie bilden, crosses + // punkt mit punkt, linie bilden, crosses GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] xy1 = new Coordinate[]{(((LineString) result1).getCoordinateN(0)), (((LineString) result1).getCoordinateN(1))}; @@ -322,7 +315,7 @@ public void test134() { Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); assertTrue(result1 instanceof LineString); assertFalse(result1.isSimple()); - // punkt mit punkt, linie bilden, crosses + // punkt mit punkt, linie bilden, crosses GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] xy1 = new Coordinate[]{(((LineString) result1).getCoordinateN(0)), (((LineString) result1).getCoordinateN(2))}; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java index b2caaea09..43cc59711 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmtestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -11,15 +14,12 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Point; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmTestData3xxTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmTestData3xxTest() { testData.add("./src/test/resources/osm-testdata/all.osm"); @@ -32,68 +32,71 @@ public void test300() { OSMEntity entity = testData.nodes().get(200000L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertTrue(result instanceof Point); - Integer entity_uid = testData.nodes().get(200000L).get(0).getUserId(); - assertTrue(entity_uid instanceof Integer); + Integer entityUid = testData.nodes().get(200000L).get(0).getUserId(); + assertTrue(entityUid instanceof Integer); } + @Test public void test301() { // Empty username on node should not happen OSMEntity entity1 = testData.nodes().get(201000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } } + @Test public void test302() { // No uid and no user name means user is anonymous // user name is not priority } + @Test public void test303() { // No uid and no user name means user is anonymous // user name is not priority } + @Test public void test304() { // negative user ids are not allowed (but -1 could have been meant as anonymous user) OSMEntity entity1 = testData.nodes().get(204000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } } + @Test public void test305() { // uid < 0 and username is inconsistent and definitely wrong OSMEntity entity1 = testData.nodes().get(205000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } } + @Test public void test306() { // 250 characters in username is okay // user name is not priority } + @Test public void test307() { // 260 characters in username is too long OSMEntity entity1 = testData.nodes().get(207000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java index d6280b47e..e53728f73 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java @@ -27,7 +27,7 @@ public class OSHDBGeometryBuilderTestOsmTestData7xxTest { private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-8; + private static final double DELTA = 1E-8; public OSHDBGeometryBuilderTestOsmTestData7xxTest() { testData.add("./src/test/resources/osm-testdata/all.osm"); @@ -89,7 +89,8 @@ public void test702() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.24 1.01,7.21 1.01,7.21 1.02,7.23 1.03,7.23 1.04,7.21 1.04,7.21 1.05,7.24 1.05,7.24 1.01)))" + "MULTIPOLYGON(((7.24 1.01,7.21 1.01,7.21 1.02,7.23 1.03,7.23 1.04,7.21 1.04,7.21 1.05," + + "7.24 1.05,7.24 1.01)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -107,8 +108,8 @@ public void test703() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.34 1.01,7.31 1.01,7.31 1.02,7.33 1.03,7.33 1.04,7.32 1.04," - + "7.32 1.05,7.34 1.05,7.34 1.01)))" + "MULTIPOLYGON(((7.34 1.01,7.31 1.01,7.31 1.02,7.33 1.03,7.33 1.04,7.32 1.04,7.32 1.05," + + "7.34 1.05,7.34 1.01)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -135,7 +136,8 @@ public void test704() throws ParseException { @Test public void test705() throws ParseException { - // Valid multipolygon relation with three ways making up an outer ring. Contains concave and convex parts. + // Valid multipolygon relation with three ways making up an outer ring. Contains concave and + // convex parts. OSMEntity entity = testData.relations().get(705900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -154,7 +156,8 @@ public void test705() throws ParseException { @Test public void test706() throws ParseException { - // Valid multipolygon relation with three ways making up two outer rings that touch in one point. + // Valid multipolygon relation with three ways making up two outer rings that touch in one + // point. OSMEntity entity = testData.relations().get(706900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof MultiPolygon); @@ -212,7 +215,8 @@ public void test708() throws ParseException { @Test public void test709() throws ParseException { - // Valid multipolygon relation with four ways making up three outer rings touching in three points. + // Valid multipolygon relation with four ways making up three outer rings touching in three + // points. OSMEntity entity = testData.relations().get(709900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof MultiPolygon); @@ -232,14 +236,14 @@ public void test709() throws ParseException { @Test public void test710() { - // Invalid multipolygon relation: Three ways make up two outer rings, but the outer rings overlap. + // Invalid multipolygon relation: Three ways make up two outer rings, but the outer rings + // overlap. OSMEntity entity1 = testData.relations().get(710900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(2, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -253,8 +257,7 @@ public void test711() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(2, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -268,8 +271,7 @@ public void test714() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(1, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -283,8 +285,7 @@ public void test715() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(2, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -294,7 +295,8 @@ public void test715() { @Test public void test720() throws ParseException { - // "Multipolygon with one outer and one inner ring. They are both oriented clockwise and have the correct role. + // "Multipolygon with one outer and one inner ring. They are both oriented clockwise and have + // the correct role. OSMEntity entity = testData.relations().get(720900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -314,25 +316,29 @@ public void test720() throws ParseException { @Test public void test721() throws ParseException { - // "Multipolygon with one outer and one inner ring. They are both oriented anti-clockwise and have the correct role. + // "Multipolygon with one outer and one inner ring. They are both oriented anti-clockwise and + // have the correct role. // the same as test(720) apart from anti-clockwise } @Test public void test722() throws ParseException { - // Multipolygon with one outer and one inner ring. The outer ring is oriented clockwise, the inner anti-clockwise. They have both the correct role. + // Multipolygon with one outer and one inner ring. The outer ring is oriented clockwise, the + // inner anti-clockwise. They have both the correct role. // the same as test(720) apart from anti-clockwise } @Test public void test723() throws ParseException { - // Multipolygon with one outer and one inner ring. The outer ring is oriented anti-clockwise, the inner clockwise. They have both the correct role + // Multipolygon with one outer and one inner ring. The outer ring is oriented anti-clockwise, + // the inner clockwise. They have both the correct role. // the same as test(722) apart from anti-clockwise } @Test public void test724() throws ParseException { - // Multipolygon with one outer and one inner ring and a bit more complex geometry and nodes not in order + // Multipolygon with one outer and one inner ring and a bit more complex geometry and nodes not + // in order OSMEntity entity = testData.relations().get(724900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -342,8 +348,8 @@ public void test724() throws ParseException { assertEquals(14, result.getCoordinates().length); // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.44 1.22,7.47 1.21,7.41 1.21,7.42 1.22,7.41 1.24,7.43 1.26,7.46 1.26,7.45 1.23,7.44 1.22)," - + "(7.43 1.22,7.42 1.24,7.44 1.25,7.45 1.24,7.43 1.22)))" + "MULTIPOLYGON(((7.44 1.22,7.47 1.21,7.41 1.21,7.42 1.22,7.41 1.24,7.43 1.26,7.46 1.26," + + "7.45 1.23,7.44 1.22),(7.43 1.22,7.42 1.24,7.44 1.25,7.45 1.24,7.43 1.22)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -366,11 +372,13 @@ public void test725() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); } + @Test public void test726() throws ParseException { // Valid multipolygon with one inner and one outer // the same as test(724) apart from anti-clockwise } + @Test public void test727() throws ParseException { // Valid multipolygon with one inner and one outer @@ -389,7 +397,8 @@ public void test728() throws ParseException { assertEquals(9, result.getCoordinates().length); // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.85 1.23,7.86 1.22,7.87 1.22,7.87 1.24,7.86 1.25,7.83 1.25,7.82 1.26,7.84 1.23,7.85 1.23)))" + "MULTIPOLYGON(((7.85 1.23,7.86 1.22,7.87 1.22,7.87 1.24,7.86 1.25,7.83 1.25,7.82 1.26," + + "7.84 1.23,7.85 1.23)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -440,7 +449,8 @@ public void test730() throws ParseException { @Test public void test731() throws ParseException { - // "Valid complex multipolygon with one outer and two inner rings made up of several ways. Roles are tagged correctly + // "Valid complex multipolygon with one outer and two inner rings made up of several ways. Roles + // are tagged correctly OSMEntity entity = testData.relations().get(731900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -451,8 +461,9 @@ public void test731() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.18 1.33,7.17 1.31,7.12 1.31,7.11 1.33,7.11 1.38,7.18 1.38,7.18 1.33)," - + "(7.17 1.32,7.12 1.32,7.12 1.36,7.13 1.36,7.13 1.33,7.16 1.33,7.16 1.34,7.17 1.35,7.17 1.32)," - + "(7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + + "(7.17 1.32,7.12 1.32,7.12 1.36,7.13 1.36,7.13 1.33,7.16 1.33,7.16 1.34,7.17 1.35," + + "7.17 1.32),(7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.15 1.36,7.15 1.37," + + "7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -460,7 +471,8 @@ public void test731() throws ParseException { @Test public void test732() throws ParseException { - // Valid multipolygon with two outer rings, one containing an inner. One ring contains a node twice in succession in data.osm + // Valid multipolygon with two outer rings, one containing an inner. One ring contains a node + // twice in succession in data.osm OSMEntity entity = testData.relations().get(732900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof MultiPolygon); @@ -499,8 +511,7 @@ public void test740() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -513,8 +524,7 @@ public void test741() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -527,8 +537,7 @@ public void test742() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -548,8 +557,7 @@ public void test744() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 2); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -563,8 +571,7 @@ public void test745() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 1); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -578,8 +585,7 @@ public void test746() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 2); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -592,8 +598,7 @@ public void test747() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -606,8 +611,7 @@ public void test748() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -620,8 +624,7 @@ public void test749() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -635,8 +638,9 @@ public void test750() throws ParseException { assertTrue(result instanceof Polygon); assertTrue(result.isValid()); assertEquals(1, ((Polygon)result).getNumInteriorRing()); - // In the result are 12 points, but it does not matter that we get 19, because the intersection is correct - // compare if coordinates of created points equals the coordinates of polygon + // In the result are 12 points, but it does not matter that we get 19, because the intersection + // is correct. + // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.01 1.51,7.01 1.57,7.06 1.57,7.06 1.51,7.01 1.51)," + "(7.02 1.52,7.02 1.55,7.04 1.55,7.05 1.55,7.05 1.52,7.03 1.52,7.02 1.52)))" @@ -653,7 +657,8 @@ public void test751() throws ParseException { assertTrue(result instanceof Polygon); assertTrue(result.isValid()); assertEquals(1, ((Polygon)result).getNumInteriorRing()); - // In the result are 11 points, but it does not matter that we get 16, because the intersection is correct + // In the result are 11 points, but it does not matter that we get 16, because the intersection + // is correct. //assertEquals(16, result.getCoordinates().length); // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( @@ -671,8 +676,7 @@ public void test752() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -685,8 +689,7 @@ public void test753() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -699,8 +702,7 @@ public void test754() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -732,8 +734,7 @@ public void test756() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -746,8 +747,7 @@ public void test757() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -863,8 +863,7 @@ public void test768() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -884,8 +883,7 @@ public void test771() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 2); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -918,8 +916,7 @@ public void test773() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -939,7 +936,8 @@ public void test774() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.42 1.73,7.42 1.75,7.44 1.75,7.44 1.73,7.42 1.73))," - + "((7.44 1.75,7.44 1.76,7.47 1.76,7.47 1.72,7.44 1.72,7.44 1.73,7.45 1.73,7.45 1.75,7.44 1.75)))" + + "((7.44 1.75,7.44 1.76,7.47 1.76,7.47 1.72,7.44 1.72,7.44 1.73,7.45 1.73,7.45 1.75," + + "7.44 1.75)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -980,8 +978,8 @@ public void test777() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.71 1.71,7.78 1.71,7.78 1.77,7.71 1.77,7.71 1.71)," - + "(7.72 1.73,7.72 1.75,7.74 1.75,7.74 1.76,7.77 1.76,7.77 1.72,7.74 1.72,7.74 1.73,7.72 1.73))," - + "((7.74 1.73,7.75 1.73,7.75 1.75,7.74 1.75,7.74 1.73)))" + + "(7.72 1.73,7.72 1.75,7.74 1.75,7.74 1.76,7.77 1.76,7.77 1.72,7.74 1.72,7.74 1.73," + + "7.72 1.73)),((7.74 1.73,7.75 1.73,7.75 1.75,7.74 1.75,7.74 1.73)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -1022,8 +1020,8 @@ public void test779() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.91 1.71,7.98 1.71,7.98 1.77,7.91 1.77,7.91 1.71)," - + "(7.92 1.73,7.92 1.75,7.94 1.75,7.94 1.76,7.97 1.76,7.97 1.72,7.94 1.72,7.94 1.73,7.92 1.73))," - + "((7.94 1.73,7.95 1.73,7.95 1.75,7.94 1.75,7.94 1.73)))" + + "(7.92 1.73,7.92 1.75,7.94 1.75,7.94 1.76,7.97 1.76,7.97 1.72,7.94 1.72,7.94 1.73," + + "7.92 1.73)),((7.94 1.73,7.95 1.73,7.95 1.75,7.94 1.75,7.94 1.73)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -1036,8 +1034,7 @@ public void test780() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1045,13 +1042,13 @@ public void test780() { @Test public void test781() { - // Multipolygon with one outer ring from single way that has different end-nodes, but they have same location + // Multipolygon with one outer ring from single way that has different end-nodes, but they have + // same location OSMEntity entity1 = testData.relations().get(781900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1059,13 +1056,13 @@ public void test781() { @Test public void test782() { - // Multipolygon with correct outer ring, but inner ring made up out of two ways where locations match but not node ids + // Multipolygon with correct outer ring, but inner ring made up out of two ways where locations + // match but not node ids OSMEntity entity1 = testData.relations().get(782900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1144,8 +1141,7 @@ public void test790() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1158,8 +1154,7 @@ public void test791() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1171,8 +1166,7 @@ public void test792() { OSMEntity entity1 = testData.relations().get(792900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1184,8 +1178,7 @@ public void test793() { OSMEntity entity1 = testData.relations().get(793900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1203,8 +1196,7 @@ public void test795() { OSMEntity entity1 = testData.relations().get(795900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java index a766ee320..f3e065e10 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java @@ -18,7 +18,7 @@ public class OSHDBGeometryBuilderMultipolygonInvalidOutersTest { private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderMultipolygonInvalidOutersTest() { testData.add("./src/test/resources/relations/invalid-outer-ring.osm"); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java index 4864615b4..0625a74ee 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.relations; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -13,16 +16,13 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderRelationOuterDirectionsTest { private final OSMXmlReader testData = new OSMXmlReader(); private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderRelationOuterDirectionsTest() { testData.add("./src/test/resources/relations/outer-directions.osm"); @@ -42,7 +42,8 @@ public void testFromPointTwoWaysGoingToDiffDirections() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -60,7 +61,8 @@ public void testToPointTwoWaysPointingFromDiffDirections() throws ParseException // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -78,7 +80,8 @@ public void testStartMatchesEnd() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -96,7 +99,8 @@ public void testEndMatchesStart() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java index 8b29eb8cb..e19e09482 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.relations; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -13,15 +16,12 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderRelationTypeNotMultipolygonTest { private final OSMXmlReader testData = new OSMXmlReader(); private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderRelationTypeNotMultipolygonTest() { testData.add("./src/test/resources/relations/relationTypeNotMultipolygon.osm"); @@ -34,13 +34,12 @@ public void testTypeRestriction() { OSMEntity entity1 = testData.relations().get(710900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -52,13 +51,12 @@ public void testTypeAssociatedStreet() { OSMEntity entity1 = testData.relations().get(710901L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof Point); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof Point); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -70,14 +68,13 @@ public void testTypePublicTransport() { OSMEntity entity1 = testData.relations().get(710902L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 4); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); assertTrue(result.getGeometryN(3) instanceof Point); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -89,13 +86,12 @@ public void testTypeBuilding() { OSMEntity entity1 = testData.relations().get(710903L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java index d32041284..be2d03667 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.tagtranslator; +import static org.junit.Assert.assertEquals; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -8,7 +10,6 @@ import org.heigit.bigspatialdata.oshdb.util.OSHDBTagKey; import org.heigit.bigspatialdata.oshdb.util.exceptions.OSHDBKeytablesNotFoundException; import org.junit.AfterClass; -import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; @@ -22,7 +23,8 @@ public static void setUpClass() throws ClassNotFoundException, SQLException { // connect to the "Big"DB TagTranslatorTest.conn = - DriverManager.getConnection("jdbc:h2:./src/test/resources/test-data;ACCESS_MODE_DATA=r", "sa", ""); + DriverManager.getConnection("jdbc:h2:./src/test/resources/test-data;ACCESS_MODE_DATA=r", + "sa", ""); } @@ -31,7 +33,8 @@ public static void breakDownClass() throws SQLException { TagTranslatorTest.conn.close(); } - public TagTranslatorTest() {} + public TagTranslatorTest() { + } @Test public void testTag2Int() throws OSHDBKeytablesNotFoundException { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java index 03200de43..444fde1c5 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java @@ -1,176 +1,185 @@ package org.heigit.bigspatialdata.oshdb.util.time; -import java.time.DateTimeException; -import org.junit.Assert; -import org.junit.Test; +import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoDateTime; +import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoPeriod; +import java.time.DateTimeException; import java.time.Duration; import java.time.Period; import java.util.Map; - -import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoDateTime; -import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoPeriod; +import org.junit.Assert; +import org.junit.Test; public class IsoDateTimeParserTest { - @Test - public void testParseIsoDateTime() { - // test allowed variants - - //Basic Dates - String[] yyyy = {"2020-01-01T00:00Z", "2020"}; - String[] yyyymm = {"2020-02-01T00:00Z", "202002"}; - String[] yyyymmdd = {"2020-02-17T00:00Z", "20200217"}; - - Assert.assertEquals(yyyy[0], parseIsoDateTime(yyyy[1]).toString()); - Assert.assertEquals(yyyymm[0], parseIsoDateTime(yyyymm[1]).toString()); - Assert.assertEquals(yyyymmdd[0], parseIsoDateTime(yyyymmdd[1]).toString()); - - //Extended Dates - String[] yyyy_mm = {"2020-02-01T00:00Z", "2020-02"}; - String[] yyyy_mm_dd = {"2020-02-17T00:00Z", "2020-02-17"}; - - Assert.assertEquals(yyyy_mm[0], parseIsoDateTime(yyyy_mm[1]).toString()); - Assert.assertEquals(yyyy_mm_dd[0], parseIsoDateTime(yyyy_mm_dd[1]).toString()); - - //Extended Date-Time - String[] yyyy_mm_dd_hh = {"2020-02-17T23:00Z", "2020-02-17T23"}; - String[] yyyy_mm_dd_hhz = {"2020-02-17T23:00Z", "2020-02-17T23Z"}; - - String[] yyyy_mm_dd_hh_mm = {"2020-02-17T23:55Z", "2020-02-17T23:55"}; - String[] yyyy_mm_dd_hh_mmz = {"2020-02-17T23:55Z", "2020-02-17T23:55Z"}; - - String[] yyyy_mm_dd_hh_mm_ss = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12"}; - String[] yyyy_mm_dd_hh_mm_ssz = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12Z"}; - - String[] yyyy_mm_dd_hh_mm_ss_sss = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999"}; - String[] yyyy_mm_dd_hh_mm_ss_sssz = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999Z"}; - - Assert.assertEquals(yyyy_mm_dd_hh[0], parseIsoDateTime(yyyy_mm_dd_hh[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hhz[0], parseIsoDateTime(yyyy_mm_dd_hhz[1]).toString()); - - Assert.assertEquals(yyyy_mm_dd_hh_mm[0], parseIsoDateTime(yyyy_mm_dd_hh_mm[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hh_mmz[0], parseIsoDateTime(yyyy_mm_dd_hh_mmz[1]).toString()); - - Assert.assertEquals(yyyy_mm_dd_hh_mm_ss[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ss[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hh_mm_ssz[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ssz[1]).toString()); - - Assert.assertEquals(yyyy_mm_dd_hh_mm_ss_sss[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ss_sss[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hh_mm_ss_sssz[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ss_sssz[1]).toString()); - - } - - - @Test(expected = OSHDBTimestampException.class) - public void throwsNegativeDateParseIsoDateTime() { - //Negative Dates - String nyyyy = "-0333"; - parseIsoDateTime(nyyyy); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsShortYearParseIsoDateTime() { - //Short Year - String yy = "12"; - parseIsoDateTime(yy); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsPosTimezoneHHParseIsoDateTime() { - String posTimezone_hh = "2020-02-17T23:55+02"; - parseIsoDateTime(posTimezone_hh); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsPosTimezoneHHMMParseIsoDateTime() { - String posTimezone_hhmm = "2020-02-17T23:55+0230"; - parseIsoDateTime(posTimezone_hhmm); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsPosTimezoneHH_MMParseIsoDateTime() { - String posTimezone_hh_mm = "2020-02-17T23:55+02:30"; - parseIsoDateTime(posTimezone_hh_mm); - } - - // - @Test(expected = OSHDBTimestampException.class) - public void throwsNegTimezoneHHParseIsoDateTime() { - String negTimezone_hh = "2020-02-17T23:55-02"; - parseIsoDateTime(negTimezone_hh); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsNegTimezoneHHMMParseIsoDateTime() { - String negTimezone_hhmm = "2020-02-17T23:55-0230"; - parseIsoDateTime(negTimezone_hhmm); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsNegTimezoneHH_MMParseIsoDateTime() { - String negTimezone_hh_mm = "2020-02-17T23:55-02:30"; - parseIsoDateTime(negTimezone_hh_mm); - } - - @Test(expected = DateTimeException.class) - public void throwsWrongDateParseIsoDateTime() { - //Wrong Date - String wrongDateTime = "2020-13-01T00:00"; - parseIsoDateTime(wrongDateTime); - } - - - @Test - public void testParseIsoPeriod() { - // test allowed variants - - // Full DateTime Period: PnYnMnDTnHnMnS, e.g P1Y3M10DT1H15M25S (1 year 3months 10 days 1 hour 15 minutes and 25 seconds) - // Full Date Period: PnYnMnD, e.g. P1Y3M10D (1 year 3 months and 10 days) - // Short Date Period: e.g PnY or PnMnD or any combination of years, months and days - // Week Period: PnW, e.g. P2W 2 weeks - // Full Time Duration: PTnHnMnS, e.g. PT1H3M25S (1 hour 3 minutes and 25 seconds) - // Short Time Duration: PTnH or any combination of hours, minutes and seconds (PT1H10S 1 hour and 10 seconds) - - String[] fullDateTimePeriod = {"P1Y3M10DT1H15M25S", "P1Y3M10D", "PT1H15M25S"}; // input, output Period, output Duration - Map fullYearMonthDayTime = parseIsoPeriod(fullDateTimePeriod[0]); - Period fullYearMonthDayTimePeriod = (Period) fullYearMonthDayTime.get("period"); - Duration fullYearMonthDayTimeDuration = (Duration) fullYearMonthDayTime.get("duration"); - Assert.assertEquals(fullDateTimePeriod[1], fullYearMonthDayTimePeriod.toString()); - Assert.assertEquals(fullDateTimePeriod[2], fullYearMonthDayTimeDuration.toString()); - - String fullDatePeriod = "P1Y3M10D"; //Period output should be same as input, Duration should be ZERO; - Map fullYearMonthDay = parseIsoPeriod(fullDatePeriod); - Period fullYearMonthDayPeriod = (Period) fullYearMonthDay.get("period"); - Duration fullYearMonthDayDuration = (Duration) fullYearMonthDay.get("duration"); - Assert.assertEquals(fullDatePeriod, fullYearMonthDayPeriod.toString()); - Assert.assertTrue(fullYearMonthDayDuration.isZero()); - - String shortDatePeriod = "P3M10D"; //Period output should be same as input, Duration should be ZERO; - Map shortMonthDay = parseIsoPeriod(shortDatePeriod); - Period shortMonthDayPeriod = (Period) shortMonthDay.get("period"); - Duration shortMonthDayDuration = (Duration) shortMonthDay.get("duration"); - Assert.assertEquals(shortDatePeriod, shortMonthDayPeriod.toString()); - Assert.assertTrue(shortMonthDayDuration.isZero()); - - String weekPeriod = "P2W"; // Period should equal 14 days, Duration should be ZERO; - Map twoWeeks = parseIsoPeriod(weekPeriod); - Period twoWeeksPeriod = (Period) twoWeeks.get("period"); - Duration twoWeeksDuration = (Duration) twoWeeks.get("duration"); - Assert.assertEquals(14, twoWeeksPeriod.getDays()); - Assert.assertTrue(twoWeeksDuration.isZero()); - - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsFormatParseIsoPeriod() { - // test throw exeption for unsupported formats - parseIsoPeriod("PT1Y2M"); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsZeroLengthParseIsoPeriod() { - //test for zero length ISOPeriod - parseIsoPeriod("PT0S"); - } + @Test + public void testParseIsoDateTime() { + // test allowed variants + + //Basic Dates + String[] yyyy = {"2020-01-01T00:00Z", "2020"}; + String[] yyyymm = {"2020-02-01T00:00Z", "202002"}; + String[] yyyymmdd = {"2020-02-17T00:00Z", "20200217"}; + + Assert.assertEquals(yyyy[0], parseIsoDateTime(yyyy[1]).toString()); + Assert.assertEquals(yyyymm[0], parseIsoDateTime(yyyymm[1]).toString()); + Assert.assertEquals(yyyymmdd[0], parseIsoDateTime(yyyymmdd[1]).toString()); + + //Extended Dates + String[] yyyyMm = {"2020-02-01T00:00Z", "2020-02"}; + String[] yyyyMmDd = {"2020-02-17T00:00Z", "2020-02-17"}; + + Assert.assertEquals(yyyyMm[0], parseIsoDateTime(yyyyMm[1]).toString()); + Assert.assertEquals(yyyyMmDd[0], parseIsoDateTime(yyyyMmDd[1]).toString()); + + //Extended Date-Time + String[] yyyyMmDdHh = {"2020-02-17T23:00Z", "2020-02-17T23"}; + String[] yyyyMmDdHhz = {"2020-02-17T23:00Z", "2020-02-17T23Z"}; + + String[] yyyyMmDdHhMm = {"2020-02-17T23:55Z", "2020-02-17T23:55"}; + String[] yyyyMmDdHhMmz = {"2020-02-17T23:55Z", "2020-02-17T23:55Z"}; + + String[] yyyyMmDdHhMmSs = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12"}; + String[] yyyyMmDdHhMmSsz = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12Z"}; + + String[] yyyyMmDdHhMmSsSss = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999"}; + String[] yyyyMmDdHhMmSsSssz = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999Z"}; + + Assert.assertEquals(yyyyMmDdHh[0], parseIsoDateTime(yyyyMmDdHh[1]).toString()); + Assert.assertEquals(yyyyMmDdHhz[0], parseIsoDateTime(yyyyMmDdHhz[1]).toString()); + + Assert.assertEquals(yyyyMmDdHhMm[0], parseIsoDateTime(yyyyMmDdHhMm[1]).toString()); + Assert.assertEquals(yyyyMmDdHhMmz[0], parseIsoDateTime(yyyyMmDdHhMmz[1]).toString()); + + Assert.assertEquals(yyyyMmDdHhMmSs[0], parseIsoDateTime(yyyyMmDdHhMmSs[1]).toString()); + Assert.assertEquals(yyyyMmDdHhMmSsz[0], parseIsoDateTime(yyyyMmDdHhMmSsz[1]).toString()); + + Assert.assertEquals(yyyyMmDdHhMmSsSss[0], parseIsoDateTime(yyyyMmDdHhMmSsSss[1]).toString()); + Assert.assertEquals(yyyyMmDdHhMmSsSssz[0], parseIsoDateTime(yyyyMmDdHhMmSsSssz[1]).toString()); + + } + + + @Test(expected = OSHDBTimestampException.class) + public void throwsNegativeDateParseIsoDateTime() { + //Negative Dates + String nyyyy = "-0333"; + parseIsoDateTime(nyyyy); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsShortYearParseIsoDateTime() { + //Short Year + String yy = "12"; + parseIsoDateTime(yy); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsPosTimezoneHhParseIsoDateTime() { + String posTimezoneHh = "2020-02-17T23:55+02"; + parseIsoDateTime(posTimezoneHh); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsPosTimezoneHhMmParseIsoDateTime() { + String posTimezoneHhmm = "2020-02-17T23:55+0230"; + parseIsoDateTime(posTimezoneHhmm); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsPosTimezoneHh_MmParseIsoDateTime() { + String posTimezoneHhMm = "2020-02-17T23:55+02:30"; + parseIsoDateTime(posTimezoneHhMm); + } + + // + @Test(expected = OSHDBTimestampException.class) + public void throwsNegTimezoneHhParseIsoDateTime() { + String negTimezoneHh = "2020-02-17T23:55-02"; + parseIsoDateTime(negTimezoneHh); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsNegTimezoneHhMmParseIsoDateTime() { + String negTimezoneHhMm = "2020-02-17T23:55-0230"; + parseIsoDateTime(negTimezoneHhMm); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsNegTimezoneHh_MmParseIsoDateTime() { + String negTimezoneHhMm = "2020-02-17T23:55-02:30"; + parseIsoDateTime(negTimezoneHhMm); + } + + @Test(expected = DateTimeException.class) + public void throwsWrongDateParseIsoDateTime() { + //Wrong Date + String wrongDateTime = "2020-13-01T00:00"; + parseIsoDateTime(wrongDateTime); + } + + + @Test + public void testParseIsoPeriod() { + // test allowed variants + + // Full DateTime Period: PnYnMnDTnHnMnS, + // e.g P1Y3M10DT1H15M25S (1 year 3months 10 days 1 hour 15 minutes and 25 seconds) + // Full Date Period: PnYnMnD, + // e.g. P1Y3M10D (1 year 3 months and 10 days) + // Short Date Period: + // e.g PnY or PnMnD or any combination of years, months and days + // Week Period: PnW, + // e.g. P2W (2 weeks) + // Full Time Duration: PTnHnMnS, + // e.g. PT1H3M25S (1 hour 3 minutes and 25 seconds) + // Short Time Duration: PTnH or any combination of hours, minutes and seconds + // e.g. PT1H10S (1 hour and 10 seconds) + + // input, output Period, output Duration + String[] fullDateTimePeriod = {"P1Y3M10DT1H15M25S", "P1Y3M10D", "PT1H15M25S"}; + Map fullYearMonthDayTime = parseIsoPeriod(fullDateTimePeriod[0]); + Period fullYearMonthDayTimePeriod = (Period) fullYearMonthDayTime.get("period"); + Duration fullYearMonthDayTimeDuration = (Duration) fullYearMonthDayTime.get("duration"); + Assert.assertEquals(fullDateTimePeriod[1], fullYearMonthDayTimePeriod.toString()); + Assert.assertEquals(fullDateTimePeriod[2], fullYearMonthDayTimeDuration.toString()); + + // Period output should be same as input, Duration should be ZERO + String fullDatePeriod = "P1Y3M10D"; + Map fullYearMonthDay = parseIsoPeriod(fullDatePeriod); + Period fullYearMonthDayPeriod = (Period) fullYearMonthDay.get("period"); + Duration fullYearMonthDayDuration = (Duration) fullYearMonthDay.get("duration"); + Assert.assertEquals(fullDatePeriod, fullYearMonthDayPeriod.toString()); + Assert.assertTrue(fullYearMonthDayDuration.isZero()); + + // Period output should be same as input, Duration should be ZERO + String shortDatePeriod = "P3M10D"; + Map shortMonthDay = parseIsoPeriod(shortDatePeriod); + Period shortMonthDayPeriod = (Period) shortMonthDay.get("period"); + Duration shortMonthDayDuration = (Duration) shortMonthDay.get("duration"); + Assert.assertEquals(shortDatePeriod, shortMonthDayPeriod.toString()); + Assert.assertTrue(shortMonthDayDuration.isZero()); + + // Period should equal 14 days, Duration should be ZERO + String weekPeriod = "P2W"; + Map twoWeeks = parseIsoPeriod(weekPeriod); + Period twoWeeksPeriod = (Period) twoWeeks.get("period"); + Duration twoWeeksDuration = (Duration) twoWeeks.get("duration"); + Assert.assertEquals(14, twoWeeksPeriod.getDays()); + Assert.assertTrue(twoWeeksDuration.isZero()); + + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsFormatParseIsoPeriod() { + // test throw exeption for unsupported formats + parseIsoPeriod("PT1Y2M"); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsZeroLengthParseIsoPeriod() { + //test for zero length ISOPeriod + parseIsoPeriod("PT0S"); + } } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java index b29072f39..1d7e5a931 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java @@ -1,14 +1,14 @@ package org.heigit.bigspatialdata.oshdb.util.time; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; -import java.util.Iterator; import java.util.List; import java.util.Set; -import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.time.OSHDBTimestamps.Interval; import org.junit.Test; @@ -16,40 +16,46 @@ public class OSHDBTimestampsTest { @Test public void testTimeIntervals() { - List startList = new ArrayList<>(); - List endList = new ArrayList<>(); - List intervalList = new ArrayList<>(); - List> expectedResultList = new ArrayList<>(); + final List startList = new ArrayList<>(); + final List endList = new ArrayList<>(); + final List intervalList = new ArrayList<>(); + final List> expectedResultList = new ArrayList<>(); startList.add("2008-01-31T12:34:56"); endList.add("2010-01-31T12:34:56"); intervalList.add(Interval.YEARLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2009-01-31T12:34:56", "2010-01-31T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2009-01-31T12:34:56", "2010-01-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-07-31T12:34:56"); intervalList.add(Interval.QUARTERLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-04-30T12:34:56", "2008-07-31T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-04-30T12:34:56", "2008-07-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-03-31T12:34:56"); intervalList.add(Interval.MONTHLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-29T12:34:56", "2008-03-31T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-02-29T12:34:56", "2008-03-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-02-14T12:34:56"); intervalList.add(Interval.WEEKLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-07T12:34:56", "2008-02-14T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-02-07T12:34:56", "2008-02-14T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-02-02T12:34:56"); intervalList.add(Interval.DAILY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-01T12:34:56", "2008-02-02T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-02-01T12:34:56", "2008-02-02T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-01-31T15:00:00"); intervalList.add(Interval.HOURLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-01-31T13:34:56", "2008-01-31T14:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-01-31T13:34:56", "2008-01-31T14:34:56")); // check if lists have the same size assertEquals(startList.size(), endList.size()); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java index ae5f3e07d..b364772f0 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java @@ -3,11 +3,12 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ + package org.heigit.bigspatialdata.oshdb.util.time; -import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter; -import java.util.Date; import static org.junit.Assert.assertEquals; + +import java.util.Date; import org.junit.Test; public class TimestampFormatterTest { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java index fcdb47494..ea370cfbd 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java @@ -13,7 +13,8 @@ public class MutableOSMEntity { private int userId; private int[] tags; - public void setEntity(long id, int version, boolean visible, long timestamp, long changeset, int userId, int[] tags) { + public void setEntity(long id, int version, boolean visible, long timestamp, + long changeset, int userId, int[] tags) { this.id = id; this.version = version; this.visible = visible; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java index f1753d1a2..b098c623e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java @@ -8,7 +8,7 @@ public long getLon() { return longitude; } - public void setLon(long longitude){ + public void setLon(long longitude) { this.longitude = longitude; } @@ -17,7 +17,7 @@ public long getLat() { return latitude; } - public void setLat(long latitude){ + public void setLat(long latitude) { this.latitude = latitude; } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java index f067bfba4..cc3e592e0 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.xmlreader; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.MultimapBuilder; +import com.google.common.io.Files; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; @@ -34,11 +39,6 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.MultimapBuilder; -import com.google.common.io.Files; public class OSMXmlReader { @@ -133,8 +133,9 @@ private void read(Document doc) throws IOException { osm.setExtension(longitude, latitude); - OSMNode oldOSM = new OSMNode(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), osm.getTimestamp(), - osm.getChangeset(), osm.getUserId(), osm.getTags(), osm.getLon(), osm.getLat()); + OSMNode oldOSM = new OSMNode(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), + osm.getTimestamp(), osm.getChangeset(), osm.getUserId(), osm.getTags(), osm.getLon(), + osm.getLat()); nodes.put(Long.valueOf(id), oldOSM); } lastId = id; @@ -165,8 +166,8 @@ private void read(Document doc) throws IOException { members[idx++] = new OSMMember(memId, OSMType.NODE, 0, data); } // osm.setExtension(members); - OSMWay oldOSM = new OSMWay(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), osm.getTimestamp(), - osm.getChangeset(), osm.getUserId(), osm.getTags(), members); + OSMWay oldOSM = new OSMWay(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), + osm.getTimestamp(), osm.getChangeset(), osm.getUserId(), osm.getTags(), members); ways.put(Long.valueOf(id), oldOSM); } lastId = id; @@ -199,9 +200,9 @@ private void read(Document doc) throws IOException { } OSMType t; - if ("node".equalsIgnoreCase(type)) + if ("node".equalsIgnoreCase(type)) { t = OSMType.NODE; - else if ("way".equalsIgnoreCase(type)) { + } else if ("way".equalsIgnoreCase(type)) { t = OSMType.WAY; } else if ("relation".equalsIgnoreCase(type)) { t = OSMType.RELATION; @@ -211,6 +212,8 @@ else if ("way".equalsIgnoreCase(type)) { // members[idx++] = new OSMMemberRelation(memId, t, r.intValue()); OSHEntity data = null; + // todo write default case + // todo add case for relation switch (t) { case NODE: if (this.nodes.containsKey(memId)) { @@ -235,7 +238,8 @@ else if ("way".equalsIgnoreCase(type)) { members[idx++] = new OSMMember(memId, t, r.intValue(), data); } // osm.setExtension(members); - OSMRelation oldOSM = new OSMRelation(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), + OSMRelation oldOSM = new OSMRelation(osm.getId(), + osm.getVersion() * (osm.isVisible() ? 1 : -1), osm.getTimestamp(), osm.getChangeset(), osm.getUserId(), osm.getTags(), members); relations.put(Long.valueOf(id), oldOSM); } @@ -246,10 +250,10 @@ else if ("way".equalsIgnoreCase(type)) { public void add(String... xmlFileUrl) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); for (String p : xmlFileUrl) { - Document doc = dBuilder.parse(p); + Document doc = docBuilder.parse(p); read(doc); } } catch (ParserConfigurationException | SAXException | IOException e) { @@ -260,7 +264,7 @@ public void add(String... xmlFileUrl) { public void add(Path... xmlFilePath) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); for (Path p : xmlFilePath) { String extension = Files.getFileExtension(p.toString()); @@ -271,7 +275,7 @@ public void add(Path... xmlFilePath) { is = new GZIPInputStream(fileStream); } - Document doc = dBuilder.parse(is); + Document doc = docBuilder.parse(is); read(doc); } }