Skip to content

Commit 0680b0d

Browse files
committed
Add tests
1 parent efe9c63 commit 0680b0d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ public void testReadAfterClose(final int len) throws Exception {
133133
}
134134
}
135135

136+
@ParameterizedTest
137+
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
138+
public void testReadByteArrayAfterClose(final int len) throws Exception {
139+
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false));
140+
final MarkShieldInputStream msis = new MarkShieldInputStream(in)) {
141+
assertEquals(len, in.available());
142+
in.close();
143+
assertEquals(0, in.read(new byte[0]));
144+
assertThrows(IOException.class, () -> in.read(new byte[2]));
145+
}
146+
}
147+
148+
@ParameterizedTest
149+
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
150+
public void testReadByteArrayIntIntAfterClose(final int len) throws Exception {
151+
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false));
152+
final MarkShieldInputStream msis = new MarkShieldInputStream(in)) {
153+
assertEquals(len, in.available());
154+
in.close();
155+
assertEquals(0, in.read(new byte[0], 0, 1));
156+
assertEquals(0, in.read(new byte[1], 0, 0));
157+
assertThrows(IOException.class, () -> in.read(new byte[2], 0, 1));
158+
}
159+
}
160+
136161
@Test
137162
public void testResetThrowsExceptionWhenUnderlyingDoesNotSupport() throws IOException {
138163
// test wrapping an underlying stream which does NOT support marking

src/test/java/org/apache/commons/io/input/NullInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void testReadByteArrayAfterClose() throws Exception {
245245
}
246246

247247
@Test
248-
public void testReadByteArrayIndexAfterClose() throws Exception {
248+
public void testReadByteArrayIntIntAfterClose() throws Exception {
249249
try (InputStream in = new NullInputStream()) {
250250
assertEquals(0, in.available());
251251
in.close();

0 commit comments

Comments
 (0)