From 7dee257218825005255ce8b8834c5b90ff690d47 Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Wed, 22 May 2024 14:06:57 -0600 Subject: [PATCH] Close zip files in tests --- .../thredds/inventory/zarr/TestMFileZip.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java b/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java index 11fc96996b..4690705b2d 100644 --- a/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java +++ b/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java @@ -47,21 +47,23 @@ public static List 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