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-io.git

commit 933e3c435e6a9014c1888a40520cf891ea3cf69b
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Jul 14 09:37:28 2024 -0400

    Add BOMInputStreamTest.testCloseHandleIOException()
---
 .../commons/io/input/AutoCloseInputStreamTest.java      | 12 +-----------
 .../org/apache/commons/io/input/BOMInputStreamTest.java |  5 +++++
 .../apache/commons/io/input/ProxyInputStreamTest.java   | 17 +++++++++++++++++
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java 
b/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
index b8ba0d076..cff14e648 100644
--- a/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
@@ -20,8 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -88,17 +86,9 @@ public class AutoCloseInputStreamTest {
         assertTrue(stream.isClosed(), "closed");
     }
 
-    @SuppressWarnings("resource")
     @Test
     public void testCloseHandleIOException() throws IOException {
-        final IOException exception = new IOException();
-        @SuppressWarnings({ "deprecation" })
-        final ProxyInputStream inputStream = 
AutoCloseInputStream.builder().setInputStream(new 
BrokenInputStream(exception)).get();
-        assertFalse(inputStream.isClosed(), "closed");
-        final ProxyInputStream spy = spy(inputStream);
-        assertThrows(IOException.class, spy::close);
-        verify(spy).handleIOException(exception);
-        assertFalse(spy.isClosed(), "closed");
+        
ProxyInputStreamTest.testCloseHandleIOException(AutoCloseInputStream.builder());
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java 
b/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
index 6a0ca0ee6..522c70b93 100644
--- a/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
@@ -262,6 +262,11 @@ public class BOMInputStreamTest {
         }
     }
 
+    @Test
+    public void testCloseHandleIOException() throws IOException {
+        
ProxyInputStreamTest.testCloseHandleIOException(BOMInputStream.builder());
+    }
+
     @Test
     public void testEmptyBufferWithBOM() throws Exception {
         final byte[] data = {};
diff --git 
a/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java 
b/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
index 7ec2b0a52..fea05aee4 100644
--- a/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
@@ -19,7 +19,11 @@ package org.apache.commons.io.input;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -28,6 +32,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.build.AbstractStreamBuilder;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -48,6 +53,18 @@ public class ProxyInputStreamTest<T extends 
ProxyInputStream> {
         }
     }
 
+    @SuppressWarnings("resource")
+    static <T, B extends AbstractStreamBuilder<T, B>> void 
testCloseHandleIOException(final AbstractStreamBuilder<T, B> builder) throws 
IOException {
+        final IOException exception = new IOException();
+        @SuppressWarnings({ "deprecation" })
+        final ProxyInputStream inputStream = (ProxyInputStream) 
builder.setInputStream(new BrokenInputStream(exception)).get();
+        assertFalse(inputStream.isClosed(), "closed");
+        final ProxyInputStream spy = spy(inputStream);
+        assertThrows(IOException.class, spy::close);
+        verify(spy).handleIOException(exception);
+        assertFalse(spy.isClosed(), "closed");
+    }
+
     @SuppressWarnings({ "resource", "unused" }) // For subclasses
     protected T createFixture() throws IOException {
         return (T) new ProxyInputStreamFixture(createProxySource());

Reply via email to