-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modify
stops.txt
to be conditionally required (#1868)
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
main/src/main/java/org/mobilitydata/gtfsvalidator/validator/MissingStopsFileValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.mobilitydata.gtfsvalidator.validator; | ||
|
||
import javax.inject.Inject; | ||
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; | ||
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice; | ||
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; | ||
import org.mobilitydata.gtfsvalidator.table.*; | ||
|
||
@GtfsValidator | ||
public class MissingStopsFileValidator extends FileValidator { | ||
|
||
private final GtfsStopTableContainer stopTableContainer; | ||
private final GtfsGeojsonFeaturesContainer geojsonFeaturesContainer; | ||
|
||
@Inject | ||
MissingStopsFileValidator( | ||
GtfsStopTableContainer table, GtfsGeojsonFeaturesContainer geojsonFeaturesContainer) { | ||
this.stopTableContainer = table; | ||
this.geojsonFeaturesContainer = geojsonFeaturesContainer; | ||
} | ||
|
||
@Override | ||
public void validate(NoticeContainer noticeContainer) { | ||
if (stopTableContainer.isMissingFile() && geojsonFeaturesContainer.isMissingFile()) { | ||
noticeContainer.addValidationNotice(new MissingRequiredFileNotice("stops.txt")); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...src/test/java/org/mobilitydata/gtfsvalidator/validator/MissingStopsFileValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.mobilitydata.gtfsvalidator.validator; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import java.util.ArrayList; | ||
import org.junit.Test; | ||
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice; | ||
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; | ||
import org.mobilitydata.gtfsvalidator.table.GtfsGeojsonFeaturesContainer; | ||
import org.mobilitydata.gtfsvalidator.table.GtfsGeojsonFileDescriptor; | ||
import org.mobilitydata.gtfsvalidator.table.GtfsStopTableContainer; | ||
import org.mobilitydata.gtfsvalidator.table.TableStatus; | ||
|
||
public class MissingStopsFileValidatorTest { | ||
@Test | ||
public void stopsTxtMissingFileShouldGenerateNotice() { | ||
// If stops.txt is missing and locations.geojson is missing, a notice should be generated | ||
NoticeContainer noticeContainer = new NoticeContainer(); | ||
GtfsGeojsonFileDescriptor descriptor = new GtfsGeojsonFileDescriptor(); | ||
GtfsGeojsonFeaturesContainer geoJsonFeaturesContainer = | ||
descriptor.createContainerForInvalidStatus(TableStatus.MISSING_FILE); | ||
GtfsStopTableContainer stopTableContainer = | ||
GtfsStopTableContainer.forStatus(TableStatus.MISSING_FILE); | ||
new MissingStopsFileValidator(stopTableContainer, geoJsonFeaturesContainer) | ||
.validate(noticeContainer); | ||
assertThat(noticeContainer.getValidationNotices()) | ||
.containsExactly(new MissingRequiredFileNotice("stops.txt")); | ||
} | ||
|
||
@Test | ||
public void stopsTxtMissingFileShouldNotGenerateNotice() { | ||
// If stops.txt is missing, but locations.geojson is present, no notice should be generated | ||
NoticeContainer noticeContainer = new NoticeContainer(); | ||
GtfsGeojsonFileDescriptor descriptor = new GtfsGeojsonFileDescriptor(); | ||
GtfsGeojsonFeaturesContainer geoJsonFeaturesContainer = | ||
descriptor.createContainerForEntities(new ArrayList<>(), noticeContainer); | ||
GtfsStopTableContainer stopTableContainer = | ||
GtfsStopTableContainer.forStatus(TableStatus.MISSING_FILE); | ||
new MissingStopsFileValidator(stopTableContainer, geoJsonFeaturesContainer) | ||
.validate(noticeContainer); | ||
assertThat(noticeContainer.getValidationNotices()).isEmpty(); | ||
} | ||
} |