This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f9d03a55 Use try-with-resources
3f9d03a55 is described below

commit 3f9d03a55d5b344466f735c8bb458425ceb2b659
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri May 17 10:18:10 2024 -0400

    Use try-with-resources
---
 .../commons/compress/archivers/zip/ZipFileTest.java  | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index b7fac2aaa..cdf81f892 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -820,15 +820,17 @@ public class ZipFileTest extends AbstractTest {
     }
 
     @Test
-    public void testSetLevelTooBigForZipArchiveOutputStream() {
-        final ZipArchiveOutputStream fixture = new ZipArchiveOutputStream(new 
ByteArrayOutputStream());
-        assertThrows(IllegalArgumentException.class, () -> 
fixture.setLevel(Deflater.BEST_COMPRESSION + 1));
+    public void testSetLevelTooBigForZipArchiveOutputStream() throws 
IOException {
+        try (ZipArchiveOutputStream fixture = new ZipArchiveOutputStream(new 
ByteArrayOutputStream())) {
+            assertThrows(IllegalArgumentException.class, () -> 
fixture.setLevel(Deflater.BEST_COMPRESSION + 1));
+        }
     }
 
     @Test
-    public void testSetLevelTooSmallForZipArchiveOutputStream() {
-        final ZipArchiveOutputStream fixture = new ZipArchiveOutputStream(new 
ByteArrayOutputStream());
+    public void testSetLevelTooSmallForZipArchiveOutputStream() throws 
IOException {
+        try (ZipArchiveOutputStream fixture = new ZipArchiveOutputStream(new 
ByteArrayOutputStream())) {
         assertThrows(IllegalArgumentException.class, () -> 
fixture.setLevel(Deflater.DEFAULT_COMPRESSION - 1));
+        }
     }
 
     @Test
@@ -874,9 +876,11 @@ public class ZipFileTest extends AbstractTest {
 
     @Test
     public void testThrowsExceptionWhenWritingPreamble() throws IOException {
-        final ZipArchiveOutputStream outputStream = new 
ZipArchiveOutputStream(new ByteArrayOutputStream());
-        outputStream.putArchiveEntry(new ZipArchiveEntry());
-        assertThrows(IllegalStateException.class, () -> 
outputStream.writePreamble(ByteUtils.EMPTY_BYTE_ARRAY));
+        try (ZipArchiveOutputStream outputStream = new 
ZipArchiveOutputStream(new ByteArrayOutputStream())) {
+            outputStream.putArchiveEntry(new ZipArchiveEntry());
+            assertThrows(IllegalStateException.class, () -> 
outputStream.writePreamble(ByteUtils.EMPTY_BYTE_ARRAY));
+            outputStream.closeArchiveEntry();
+        }
     }
 
     @Test

Reply via email to