Skip to content

Commit

Permalink
Adds unit test for GroupStop's geometry and encompassingAreaGeometry.
Browse files Browse the repository at this point in the history
  • Loading branch information
eibakke committed Feb 1, 2024
1 parent 36ad8fc commit c0ebcbe
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
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;
import org.opentripplanner.transit.service.StopModel;

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");
Expand All @@ -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());
Expand Down

0 comments on commit c0ebcbe

Please sign in to comment.