diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java index b084767..56ef0c6 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java @@ -78,7 +78,9 @@ public class StreetAddressTest extends Test { @Override public void visit(Node node) { - realVisit(node); + if (node.isLatLonKnown()) { + realVisit(node); + } } @Override @@ -164,7 +166,7 @@ public class StreetAddressTest extends Test { } } - private static Collection getWayNames(Way way) { + private static Collection getWayNames(IPrimitive way) { return way.getInterestingTags().entrySet().stream() .filter(e -> (e.getKey().contains("name") || e.getKey().contains("ref")) && !e.getKey().contains("tiger")) @@ -204,24 +206,25 @@ public class StreetAddressTest extends Test { * way. */ static Pair distanceToWay(Way way, OsmPrimitive prim) { - final Node[] nodes; + final ILatLon[] nodes; if (prim instanceof Node) { - nodes = new Node[] { (Node) prim }; + nodes = new ILatLon[] { (Node) prim }; } else if (prim instanceof Way) { - nodes = ((Way) prim).getNodes().toArray(new Node[0]); + nodes = ((Way) prim).getNodes().toArray(new ILatLon[0]); } else if (prim instanceof Relation) { - nodes = ((Relation) prim).getMemberPrimitives().stream().filter(p -> p instanceof Node || p instanceof Way) - .flatMap(p -> p instanceof Node ? Stream.of((Node) p) : ((Way) p).getNodes().stream()) - .toArray(Node[]::new); + nodes = ((Relation) prim).getMemberPrimitives().stream() + .filter(p -> p instanceof ILatLon || p instanceof Way) + .flatMap(p -> p instanceof ILatLon ? Stream.of((ILatLon) p) : ((Way) p).getNodes().stream()) + .toArray(ILatLon[]::new); } else { throw new IllegalArgumentException("Unknown primitive type: " + prim.getClass()); } double dist = Double.NaN; - List wayNodes = way.getNodes(); + List wayNodes = way.getNodes(); for (int i = 0; i < wayNodes.size() - 1; i++) { - final Node a = wayNodes.get(i); - final Node b = wayNodes.get(i + 1); - for (Node node : nodes) { + final ILatLon a = wayNodes.get(i); + final ILatLon b = wayNodes.get(i + 1); + for (ILatLon node : nodes) { double tDist = getSegmentNodeDistSq(a, b, node); if (Double.isNaN(dist) || (!Double.isNaN(tDist) && tDist < dist)) { dist = tDist; diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java index a38b8c7..bdd7d96 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java @@ -1,6 +1,7 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.mapwithai.data.validation.tests; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertSame; @@ -10,7 +11,6 @@ import java.lang.reflect.Method; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.osm.AbstractPrimitive; @@ -19,19 +19,15 @@ import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.data.validation.OsmValidator; -import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; +import org.openstreetmap.josm.testutils.annotations.Projection; import org.openstreetmap.josm.tools.Pair; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -@BasicPreferences // Needed due to OsmValidator static initialization initializing tests which in - // turn need preferences +// Needed due to OsmValidator static initialization initializing tests which in turn need preferences +@BasicPreferences +@Projection class StreetAddressTestTest { private final static String ADDR_STREET = "addr:street"; - @RegisterExtension - @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - static JOSMTestRules test = new JOSMTestRules().projection(); @BeforeAll static void setup() { @@ -130,4 +126,16 @@ class StreetAddressTestTest { assertTrue(BBox.bboxesAreFunctionallyEqual(bbox, new BBox(-0.01, -0.01, 0.01, 0.01), 0.0)); } + /** + * Non-regression test for + * #23062 + */ + @Test + void testNonRegression23062() { + final StreetAddressTest test = new StreetAddressTest(); + final Node node = new Node(); + node.put(ADDR_STREET, "Test Road 1"); + assertDoesNotThrow(() -> test.visit(node)); + assertTrue(test.getErrors().isEmpty()); + } }