Skip to content

Commit

Permalink
refactor(GTFSFeedTest.java): Updated to move common code to generic m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
Robin Beer authored and Robin Beer committed Aug 8, 2023
1 parent 4a80268 commit 6b1d9a1
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions src/test/java/com/conveyal/gtfs/GTFSFeedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ public static void setUpClass() {
*/
@Test
public void canDoRoundtripLoadAndWriteToZipFile() throws IOException {
// create a temp file for this test
File outZip = File.createTempFile("fake-agency-output", ".zip");

// delete file to make sure we can assert that this program created the file
outZip.delete();

GTFSFeed feed = GTFSFeed.fromFile(simpleGtfsZipFileName);
feed.toFile(outZip.getAbsolutePath());
feed.close();
assertThat(outZip.exists(), is(true));

// assert that rows of data were written to files within the zipfile
ZipFile zip = new ZipFile(outZip);

FileTestCase[] fileTestCases = {
// agency.txt
new FileTestCase(
Expand Down Expand Up @@ -110,32 +96,15 @@ public void canDoRoundtripLoadAndWriteToZipFile() throws IOException {
}
)
};
TestUtils.lookThroughFiles(fileTestCases, zip);
// Close the zip file so it can be deleted.
zip.close();
// delete file to make sure we can assert that this program created the file
outZip.delete();
loadAndWriteToZipFile(simpleGtfsZipFileName, fileTestCases);

}

/**
* Make sure a round-trip of loading a GTFS flex zip file and then writing another zip file can be performed.
*/
@Test
void canDoRoundTripLoadAndWriteToFlexZipFile() throws IOException {
// create a temp file for this test
File outZip = File.createTempFile("fake-agency-with-flex-output", ".zip");

// delete file to make sure we can assert that this program created the file
outZip.delete();

GTFSFeed feed = GTFSFeed.fromFile(simpleFlexGtfsZipFileName);
feed.toFile(outZip.getAbsolutePath());
feed.close();
assertThat(outZip.exists(), is(true));

// assert that rows of data were written to files within the zip file.
ZipFile zip = new ZipFile(outZip);

FileTestCase[] fileTestCases = {
// agency.txt
new FileTestCase(
Expand Down Expand Up @@ -208,6 +177,27 @@ void canDoRoundTripLoadAndWriteToFlexZipFile() throws IOException {
}
)
};
loadAndWriteToZipFile(simpleFlexGtfsZipFileName, fileTestCases);
}

/**
* Load feed and then write to zip file. Once complete, perform tests.
*/
void loadAndWriteToZipFile(String zipFileName, FileTestCase[] fileTestCases) throws IOException {
// create a temp file for this test
File outZip = File.createTempFile(zipFileName, ".zip");

// delete file to make sure we can assert that this program created the file
outZip.delete();

GTFSFeed feed = GTFSFeed.fromFile(zipFileName);
feed.toFile(outZip.getAbsolutePath());
feed.close();
assertThat(outZip.exists(), is(true));

// assert that rows of data were written to files within the zip file.
ZipFile zip = new ZipFile(outZip);

TestUtils.lookThroughFiles(fileTestCases, zip);
// Close the zip file so it can be deleted.
zip.close();
Expand Down

0 comments on commit 6b1d9a1

Please sign in to comment.