You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/09/04 12:18:11 UTC

[commons-compress] 06/19: Use try-with-resources

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

commit 331de2967a2d74eee7d78e463ff51449d1b9287b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Sep 3 08:20:13 2023 -0400

    Use try-with-resources
---
 .../archivers/sevenz/AES256SHA256DecoderTest.java  | 27 ++++++++++------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
index beb25e7e..783d6385 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
@@ -28,7 +28,6 @@ import java.io.ObjectInputStream;
 
 import org.junit.jupiter.api.Test;
 
-
 /**
  * Unit tests for class {@link AES256SHA256Decoder}.
  *
@@ -36,23 +35,21 @@ import org.junit.jupiter.api.Test;
  **/
 public class AES256SHA256DecoderTest {
 
-
     @Test
-    public void testDecodeWithNonEmptyString() {
+    public void testDecodeWithNonEmptyString() throws IOException {
 
         final AES256SHA256Decoder aES256SHA256Decoder = new AES256SHA256Decoder();
-        final BufferedInputStream bufferedInputStream = new BufferedInputStream(null, 3138);
-        final Coder coder = new Coder();
-        final byte[] byteArray = new byte[8];
-        byteArray[1] = (byte) (-72);
-        coder.properties = byteArray;
-        final InputStream inputStream = aES256SHA256Decoder.decode("x", bufferedInputStream, 3138, coder, coder.properties,
-                Integer.MAX_VALUE);
-
-        final IOException e = assertThrows(IOException.class, () -> new ObjectInputStream(inputStream), "Expecting exception: IOException");
-        assertEquals("Salt size + IV size too long in x", e.getMessage());
-        assertEquals("org.apache.commons.compress.archivers.sevenz.AES256SHA256Decoder$1", e.getStackTrace()[0].getClassName());
+        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(null, 3138)) {
+            final Coder coder = new Coder();
+            final byte[] byteArray = new byte[8];
+            byteArray[1] = (byte) (-72);
+            coder.properties = byteArray;
+            try (InputStream inputStream = aES256SHA256Decoder.decode("x", bufferedInputStream, 3138, coder, coder.properties, Integer.MAX_VALUE)) {
+                final IOException e = assertThrows(IOException.class, () -> new ObjectInputStream(inputStream), "Expecting exception: IOException");
+                assertEquals("Salt size + IV size too long in x", e.getMessage());
+                assertEquals("org.apache.commons.compress.archivers.sevenz.AES256SHA256Decoder$1", e.getStackTrace()[0].getClassName());
+            }
+        }
     }
 
-
 }