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
The following commit(s) were added to refs/heads/master by this push: new 0680b0d06 Add tests 0680b0d06 is described below commit 0680b0d06e8548735bcd86bb9286db839f4a1b1e Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Aug 7 15:13:45 2024 -0400 Add tests --- .../io/input/MarkShieldInputStreamTest.java | 25 ++++++++++++++++++++++ .../commons/io/input/NullInputStreamTest.java | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java b/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java index 9f9ea5337..4ec84eb73 100644 --- a/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java @@ -133,6 +133,31 @@ public class MarkShieldInputStreamTest { } } + @ParameterizedTest + @MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME) + public void testReadByteArrayAfterClose(final int len) throws Exception { + try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false)); + final MarkShieldInputStream msis = new MarkShieldInputStream(in)) { + assertEquals(len, in.available()); + in.close(); + assertEquals(0, in.read(new byte[0])); + assertThrows(IOException.class, () -> in.read(new byte[2])); + } + } + + @ParameterizedTest + @MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME) + public void testReadByteArrayIntIntAfterClose(final int len) throws Exception { + try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false)); + final MarkShieldInputStream msis = new MarkShieldInputStream(in)) { + assertEquals(len, in.available()); + in.close(); + assertEquals(0, in.read(new byte[0], 0, 1)); + assertEquals(0, in.read(new byte[1], 0, 0)); + assertThrows(IOException.class, () -> in.read(new byte[2], 0, 1)); + } + } + @Test public void testResetThrowsExceptionWhenUnderlyingDoesNotSupport() throws IOException { // test wrapping an underlying stream which does NOT support marking diff --git a/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java b/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java index ce55398c1..2f196cb26 100644 --- a/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java @@ -245,7 +245,7 @@ public class NullInputStreamTest { } @Test - public void testReadByteArrayIndexAfterClose() throws Exception { + public void testReadByteArrayIntIntAfterClose() throws Exception { try (InputStream in = new NullInputStream()) { assertEquals(0, in.available()); in.close();