Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
* <li>{@link MissingRequiredFieldNotice} - {@code from_stop_id} is missing or {@code to_stop_id}
* is missing for all transfer types except for in-seat transfer types
* </ul>
*
* <p>An empty {@code transfer_type} means a recommended transfer point, which is the same as {@code
* transfer_type=0}, so both stop ids are required for it as well.
*/
@GtfsValidator
public class TransferStopIdsConditionalValidator extends FileValidator {
Expand All @@ -49,9 +52,7 @@ public TransferStopIdsConditionalValidator(GtfsTransferTableContainer transfersC
@Override
public void validate(NoticeContainer noticeContainer) {
for (GtfsTransfer transfer : transfersContainer.getEntities()) {
if (transfer.hasTransferType()) {
validateTransferEntity(transfer, noticeContainer);
}
validateTransferEntity(transfer, noticeContainer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,42 @@ public void testTransferFromStopIdNoInSeatTransfer() {
noticeContainer.getValidationNotices().clear();
}
}

/**
* This test is used to verify that the validator generates a notice when the stop ids are missing
* and the {@code transfer_type} is empty, which is a recommended transfer point.
*/
@Test
public void testTransferMissingStopIdsEmptyTransferType() {
GtfsTransferTableContainer gtfsTransferTableContainer =
GtfsTransferTableContainer.forEntities(
ImmutableList.of(new GtfsTransfer.Builder().build()), noticeContainer);

new TransferStopIdsConditionalValidator(gtfsTransferTableContainer).validate(noticeContainer);

assertThat(noticeContainer.getValidationNotices())
.containsExactlyElementsIn(
Arrays.asList(
new MissingRequiredFieldNotice(
GtfsTransfer.FILENAME, 0, GtfsTransfer.FROM_STOP_ID_FIELD_NAME),
new MissingRequiredFieldNotice(
GtfsTransfer.FILENAME, 0, GtfsTransfer.TO_STOP_ID_FIELD_NAME)));
}

/**
* This test is used to verify that the validator does not generate a notice when the stop ids are
* present and the {@code transfer_type} is empty.
*/
@Test
public void testTransferStopIdsPresentEmptyTransferTypeNoNotice() {
GtfsTransferTableContainer gtfsTransferTableContainer =
GtfsTransferTableContainer.forEntities(
ImmutableList.of(
new GtfsTransfer.Builder().setFromStopId("stop1").setToStopId("stop2").build()),
noticeContainer);

new TransferStopIdsConditionalValidator(gtfsTransferTableContainer).validate(noticeContainer);

assertThat(noticeContainer.getValidationNotices()).isEmpty();
}
}