Skip to content

Commit 3c35761

Browse files
committed
test: added coverage
1 parent 139f080 commit 3c35761

File tree

4 files changed

+319
-31
lines changed

4 files changed

+319
-31
lines changed

main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsGeoJsonFeature.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public final class GtfsGeoJsonFeature implements GtfsEntity {
3131

3232
public GtfsGeoJsonFeature() {}
3333

34+
private GtfsGeoJsonFeature(Builder builder) {
35+
this.featureId = builder.featureId;
36+
this.geometryType = builder.geometryType;
37+
this.geometryDefinition = builder.geometryDefinition;
38+
this.stopName = builder.stopName;
39+
this.stopDesc = builder.stopDesc;
40+
}
41+
3442
// TODO: Change the interface hierarchy so we dont need this. It's not relevant for geojson
3543
@Override
3644
public int csvRowNumber() {
@@ -104,4 +112,42 @@ public Boolean hasStopDesc() {
104112
public void setStopDesc(@Nullable String stopDesc) {
105113
this.stopDesc = stopDesc;
106114
}
115+
116+
/** Builder class for GtfsGeoJsonFeature. */
117+
public static class Builder {
118+
private String featureId;
119+
private GeometryType geometryType;
120+
private Geometry geometryDefinition;
121+
private String stopName;
122+
private String stopDesc;
123+
124+
public Builder featureId(String featureId) {
125+
this.featureId = featureId;
126+
return this;
127+
}
128+
129+
public Builder geometryType(GeometryType geometryType) {
130+
this.geometryType = geometryType;
131+
return this;
132+
}
133+
134+
public Builder geometryDefinition(Geometry geometryDefinition) {
135+
this.geometryDefinition = geometryDefinition;
136+
return this;
137+
}
138+
139+
public Builder stopName(String stopName) {
140+
this.stopName = stopName;
141+
return this;
142+
}
143+
144+
public Builder stopDesc(String stopDesc) {
145+
this.stopDesc = stopDesc;
146+
return this;
147+
}
148+
149+
public GtfsGeoJsonFeature build() {
150+
return new GtfsGeoJsonFeature(this);
151+
}
152+
}
107153
}

main/src/main/java/org/mobilitydata/gtfsvalidator/validator/OverlappingPickupDropOffZoneValidator.java

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;
44

5+
import java.util.ArrayList;
56
import java.util.Collection;
7+
import java.util.List;
68
import java.util.Map;
79
import javax.inject.Inject;
810
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
@@ -33,14 +35,14 @@ public void validate(NoticeContainer noticeContainer) {
3335
// For all entities with the same trip id
3436
for (Map.Entry<String, Collection<GtfsStopTime>> entry :
3537
stopTimeTableContainer.byTripIdMap().asMap().entrySet()) {
36-
Collection<GtfsStopTime> stopTimesForTrip = entry.getValue();
38+
List<GtfsStopTime> stopTimesForTrip = new ArrayList<>(entry.getValue());
3739
// Checking entities two by two
38-
for (GtfsStopTime stopTime1 : stopTimesForTrip) {
39-
for (GtfsStopTime stopTime2 : stopTimesForTrip) {
40-
// If the two entities are the same, skip
41-
if (stopTime1.equals(stopTime2)) {
42-
continue;
43-
}
40+
// Checking entities two by two
41+
for (int i = 0; i < stopTimesForTrip.size(); i++) {
42+
GtfsStopTime stopTime1 = stopTimesForTrip.get(i);
43+
for (int j = i + 1; j < stopTimesForTrip.size(); j++) {
44+
GtfsStopTime stopTime2 = stopTimesForTrip.get(j);
45+
4446
// If the two entities have overlapping pickup/drop-off windows
4547
if (!(stopTime1.hasEndPickupDropOffWindow()
4648
&& stopTime1.hasStartPickupDropOffWindow()
@@ -50,12 +52,18 @@ public void validate(NoticeContainer noticeContainer) {
5052
&& stopTime2.hasLocationId())) {
5153
continue;
5254
}
55+
56+
if (stopTime1.locationId().equals(stopTime2.locationId())) {
57+
continue;
58+
}
59+
5360
if (stopTime1.startPickupDropOffWindow().isAfter(stopTime2.endPickupDropOffWindow())
5461
|| stopTime1.endPickupDropOffWindow().isBefore(stopTime2.startPickupDropOffWindow())
5562
|| stopTime1.endPickupDropOffWindow().equals(stopTime2.startPickupDropOffWindow())
5663
|| stopTime1.startPickupDropOffWindow().equals(stopTime2.endPickupDropOffWindow())) {
5764
continue;
5865
}
66+
5967
// If the two entities have overlapping pickup/drop-off zones
6068
GtfsGeoJsonFeature stop1GeoJsonFeature =
6169
geoJsonFeaturesContainer.byLocationId(stopTime1.locationId());
@@ -64,12 +72,16 @@ public void validate(NoticeContainer noticeContainer) {
6472
if (stop1GeoJsonFeature == null || stop2GeoJsonFeature == null) {
6573
continue;
6674
}
75+
6776
if (stop1GeoJsonFeature.geometryOverlaps(stop2GeoJsonFeature)) {
6877
noticeContainer.addValidationNotice(
6978
new OverlappingZoneAndPickupDropOffWindowNotice(
79+
stopTime1.tripId(),
80+
stopTime1.stopSequence(),
7081
stopTime1.locationId(),
7182
stopTime1.startPickupDropOffWindow(),
7283
stopTime1.endPickupDropOffWindow(),
84+
stopTime2.stopSequence(),
7385
stopTime2.locationId(),
7486
stopTime2.startPickupDropOffWindow(),
7587
stopTime2.endPickupDropOffWindow()));
@@ -89,38 +101,52 @@ public void validate(NoticeContainer noticeContainer) {
89101
severity = ERROR,
90102
files = @GtfsValidationNotice.FileRefs({GtfsGeoJsonFeature.class, GtfsStopTime.class}))
91103
static class OverlappingZoneAndPickupDropOffWindowNotice extends ValidationNotice {
104+
/** The `trip_id` of the entities. */
105+
private final String tripId;
106+
107+
/** The `stop_sequence` of the first entity in `stop_times.txt`. */
108+
private final Integer stopSequence1;
92109

93110
/** The `location_id` of the first entity. */
94-
private final String locationIdA;
111+
private final String locationId1;
95112

96113
/** The `start_pickup_drop_off_window` of the first entity in `stop_times.txt`. */
97-
private final GtfsTime startPickupDropOffWindowA;
114+
private final GtfsTime startPickupDropOffWindow1;
98115

99116
/** The `end_pickup_drop_off_window` of the first entity in `stop_times.txt`. */
100-
private final GtfsTime endPickupDropOffWindowA;
117+
private final GtfsTime endPickupDropOffWindow1;
118+
119+
/** The `stop_sequence` of the second entity in `stop_times.txt`. */
120+
private final Integer stopSequence2;
101121

102122
/** The `location_id` of the second entity. */
103-
private final String locationIdB;
123+
private final String locationId2;
104124

105125
/** The `start_pickup_drop_off_window` of the second entity in `stop_times.txt`. */
106-
private final GtfsTime startPickupDropOffWindowB;
126+
private final GtfsTime startPickupDropOffWindow2;
107127

108128
/** The `end_pickup_drop_off_window` of the second entity in `stop_times.txt`. */
109-
private final GtfsTime endPickupDropOffWindowB;
129+
private final GtfsTime endPickupDropOffWindow2;
110130

111131
OverlappingZoneAndPickupDropOffWindowNotice(
112-
String locationIdA,
113-
GtfsTime startPickupDropOffWindowA,
114-
GtfsTime endPickupDropOffWindowA,
115-
String locationIdB,
116-
GtfsTime startPickupDropOffWindowB,
117-
GtfsTime endPickupDropOffWindowB) {
118-
this.locationIdA = locationIdA;
119-
this.startPickupDropOffWindowA = startPickupDropOffWindowA;
120-
this.endPickupDropOffWindowA = endPickupDropOffWindowA;
121-
this.locationIdB = locationIdB;
122-
this.startPickupDropOffWindowB = startPickupDropOffWindowB;
123-
this.endPickupDropOffWindowB = endPickupDropOffWindowB;
132+
String tripId,
133+
Integer stopSequence1,
134+
String locationId1,
135+
GtfsTime startPickupDropOffWindow1,
136+
GtfsTime endPickupDropOffWindow1,
137+
Integer stopSequence2,
138+
String locationId2,
139+
GtfsTime startPickupDropOffWindow2,
140+
GtfsTime endPickupDropOffWindow2) {
141+
this.tripId = tripId;
142+
this.stopSequence1 = stopSequence1;
143+
this.locationId1 = locationId1;
144+
this.startPickupDropOffWindow1 = startPickupDropOffWindow1;
145+
this.endPickupDropOffWindow1 = endPickupDropOffWindow1;
146+
this.stopSequence2 = stopSequence2;
147+
this.locationId2 = locationId2;
148+
this.startPickupDropOffWindow2 = startPickupDropOffWindow2;
149+
this.endPickupDropOffWindow2 = endPickupDropOffWindow2;
124150
}
125151
}
126152
}

main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public void testNoticeClassFieldNames() {
8080
"departureTime1",
8181
"distanceKm",
8282
"endFieldName",
83-
"endPickupDropOffWindowA",
84-
"endPickupDropOffWindowB",
83+
"endPickupDropOffWindow1",
84+
"endPickupDropOffWindow2",
8585
"endValue",
8686
"entityCount",
8787
"entityId",
@@ -122,8 +122,8 @@ public void testNoticeClassFieldNames() {
122122
"lineIndex",
123123
"locationGroupId",
124124
"locationId",
125-
"locationIdA",
126-
"locationIdB",
125+
"locationId1",
126+
"locationId2",
127127
"locationType",
128128
"locationTypeName",
129129
"locationTypeValue",
@@ -186,8 +186,8 @@ public void testNoticeClassFieldNames() {
186186
"specifiedField",
187187
"speedKph",
188188
"startFieldName",
189-
"startPickupDropOffWindowA",
190-
"startPickupDropOffWindowB",
189+
"startPickupDropOffWindow1",
190+
"startPickupDropOffWindow2",
191191
"startValue",
192192
"stopCsvRowNumber",
193193
"stopDesc",

0 commit comments

Comments
 (0)