Skip to content

Commit

Permalink
Close zip files in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tdrwenski committed May 23, 2024
1 parent 9711716 commit 7dee257
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ public static List<Integer[]> getTestParameters() {

@Test
public void shouldWriteZipToStream() throws IOException {
final ZipFile zipFile = createTemporaryZipFile(expectedSize, expectedNumberOfFiles);
final MFileZip mFile = new MFileZip(zipFile.getName());
try (ZipFile zipFile = createTemporaryZipFile(expectedSize, expectedNumberOfFiles)) {
final MFileZip mFile = new MFileZip(zipFile.getName());

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mFile.writeToStream(outputStream);
assertThat(outputStream.size()).isEqualTo(expectedSize * expectedNumberOfFiles);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mFile.writeToStream(outputStream);
assertThat(outputStream.size()).isEqualTo(expectedSize * expectedNumberOfFiles);
}
}
}

public static class TestMFileZipNonParameterized {
@Test
public void shouldReturnTrueForExistingFile() throws IOException {
final ZipFile zipFile = createTemporaryZipFile(2, 0);
final MFileZip mFile = new MFileZip(zipFile.getName());
assertThat(mFile.exists()).isEqualTo(true);
try (ZipFile zipFile = createTemporaryZipFile(2, 0)) {
final MFileZip mFile = new MFileZip(zipFile.getName());
assertThat(mFile.exists()).isEqualTo(true);
}
}

@Test
Expand Down

0 comments on commit 7dee257

Please sign in to comment.