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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9741fb8  Test cases for close() methods added in 2.7
9741fb8 is described below

commit 9741fb8508c422668e6975304e41e5a13e0e704c
Author: Sebb <s...@apache.org>
AuthorDate: Wed Aug 5 17:49:35 2020 +0100

    Test cases for close() methods added in 2.7
---
 .../org/apache/commons/io/IOUtilsTestCase.java     | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java 
b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
index 06f454d..1c9c627 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -61,9 +61,11 @@ import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.io.function.IOConsumer;
 import org.apache.commons.io.output.AppendableWriter;
 import org.apache.commons.io.output.StringBuilderWriter;
 import org.apache.commons.io.testtools.TestUtils;
+import org.apache.commons.io.testtools.YellOnCloseReader;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
@@ -138,6 +140,34 @@ public class IOUtilsTestCase {
         }
     }
 
+    @Test public void testClose() {
+        assertDoesNotThrow(() -> IOUtils.close((Closeable) null));
+        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s")));
+        assertThrows(IOException.class, () -> IOUtils.close(new 
YellOnCloseReader(new StringReader("s"))));
+    }
+
+    @Test public void testCloseConsumer() {
+        Closeable nulCloseable = null;
+        assertDoesNotThrow(() -> IOUtils.close(nulCloseable, null)); // null 
consumer
+        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), null)); 
// null consumer
+        assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new 
StringReader("s")), null)); // null consumer
+
+        final IOConsumer<IOException> nullConsumer = null; // null consumer 
doesn't throw
+        assertDoesNotThrow(() -> IOUtils.close(nulCloseable, nullConsumer));
+        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), 
nullConsumer));
+        assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new 
StringReader("s")), nullConsumer));
+
+        final IOConsumer<IOException> silentConsumer = i -> {}; // silent 
consumer doesn't throw
+        assertDoesNotThrow(() -> IOUtils.close(nulCloseable, silentConsumer));
+        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), 
silentConsumer));
+        assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new 
StringReader("s")), silentConsumer));
+
+        final IOConsumer<IOException> noisyConsumer = i -> {throw i;}; // 
consumer passes on the throw
+        assertDoesNotThrow(() -> IOUtils.close(nulCloseable, noisyConsumer)); 
// no throw
+        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), 
noisyConsumer)); // no throw
+        assertThrows(IOException.class, () -> IOUtils.close(new 
YellOnCloseReader(new StringReader("s")),noisyConsumer)); // closeable throws
+    }
+
     @Test public void testCloseQuietly_AllCloseableIOException() {
         final Closeable closeable = () -> {
             throw new IOException();

Reply via email to