From c0ebcbef4a88af8752ad3dd26bc866932edd5bf2 Mon Sep 17 00:00:00 2001 From: eibakke Date: Thu, 1 Feb 2024 13:56:49 +0100 Subject: [PATCH] Adds unit test for GroupStop's geometry and encompassingAreaGeometry. --- .../transit/model/site/GroupStopBuilder.java | 7 ++- .../transit/model/site/GroupStopTest.java | 58 ++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/model/site/GroupStopBuilder.java b/src/main/java/org/opentripplanner/transit/model/site/GroupStopBuilder.java index a8db22b1368..64cad9325d1 100644 --- a/src/main/java/org/opentripplanner/transit/model/site/GroupStopBuilder.java +++ b/src/main/java/org/opentripplanner/transit/model/site/GroupStopBuilder.java @@ -75,7 +75,12 @@ public GroupStopBuilder addLocation(StopLocation location) { ) ) { throw new RuntimeException( - "Unsupported location for GroupStop. Must be Regular or FlexibleArea." + String.format( + "Unsupported location for %s. Must be %s or %s.", + GroupStop.class.getSimpleName(), + StopType.REGULAR, + StopType.FLEXIBLE_AREA + ) ); } diff --git a/src/test/java/org/opentripplanner/transit/model/site/GroupStopTest.java b/src/test/java/org/opentripplanner/transit/model/site/GroupStopTest.java index 17938131eef..dcf9bc3aeed 100644 --- a/src/test/java/org/opentripplanner/transit/model/site/GroupStopTest.java +++ b/src/test/java/org/opentripplanner/transit/model/site/GroupStopTest.java @@ -6,7 +6,12 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; +import java.util.Objects; import org.junit.jupiter.api.Test; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.geom.Geometry; +import org.opentripplanner.framework.geometry.GeometryUtils; import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.transit.model._data.TransitModelForTest; @@ -14,7 +19,7 @@ class GroupStopTest { - private static TransitModelForTest TEST_MODEL = TransitModelForTest.of(); + private static final TransitModelForTest TEST_MODEL = TransitModelForTest.of(); private static final String ID = "1"; private static final I18NString NAME = new NonLocalizedString("name"); @@ -27,6 +32,57 @@ class GroupStopTest { .addLocation(STOP_LOCATION) .build(); + @Test + void testGroupStopGeometry() { + StopLocation stopLocation1 = TEST_MODEL.stop("1:stop", 1d, 1d).build(); + StopLocation stopLocation2 = TEST_MODEL.stop("2:stop", 2d, 2d).build(); + + GroupStop groupStop = StopModel + .of() + .groupStop(TransitModelForTest.id(ID)) + .withName(NAME) + .addLocation(stopLocation1) + .addLocation(stopLocation2) + .build(); + + Geometry groupStopGeometry1 = Objects.requireNonNull(groupStop.getGeometry()).getGeometryN(0); + assertEquals(stopLocation1.getGeometry(), groupStopGeometry1); + + Geometry groupStopGeometry2 = Objects.requireNonNull(groupStop.getGeometry()).getGeometryN(1); + assertEquals(stopLocation2.getGeometry(), groupStopGeometry2); + } + + @Test + void testGroupStopEncompassingAreaGeometry() { + Geometry encompassingAreaGeometry = GeometryUtils + .getGeometryFactory() + .toGeometry(new Envelope(1d, 2d, 1d, 2d)); + + StopLocation stopLocation = TEST_MODEL + .stop( + "1:stop", + encompassingAreaGeometry.getCentroid().getX(), + encompassingAreaGeometry.getCentroid().getY() + ) + .build(); + + GroupStop groupStop = StopModel + .of() + .groupStop(TransitModelForTest.id(ID)) + .withName(NAME) + .addLocation(stopLocation) + .withEncompassingAreaGeometries(List.of(encompassingAreaGeometry)) + .build(); + + Geometry groupStopGeometry = Objects.requireNonNull(groupStop.getGeometry()).getGeometryN(0); + assertEquals(stopLocation.getGeometry(), groupStopGeometry); + + assertEquals( + encompassingAreaGeometry, + groupStop.getEncompassingAreaGeometry().orElseThrow().getGeometryN(0) + ); + } + @Test void copy() { assertEquals(ID, subject.getId().getId());