Skip to content

Commit fe4f775

Browse files
committed
Add CloseShieldInputStream tests
1 parent 22b287f commit fe4f775

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626

27+
import org.apache.commons.io.IOUtils;
2728
import org.junit.jupiter.api.BeforeEach;
2829
import org.junit.jupiter.api.Test;
2930

@@ -52,6 +53,23 @@ public void close() {
5253
closed = false;
5354
}
5455

56+
@Test
57+
public void testAvailableAfterCose() throws Exception {
58+
InputStream shadow;
59+
try (InputStream in = CloseShieldInputStream.wrap(byteArrayInputStream)) {
60+
assertEquals(3, in.available());
61+
shadow = in;
62+
}
63+
assertEquals(0, shadow.available());
64+
}
65+
66+
@Test
67+
public void testAvailableAfterOpen() throws Exception {
68+
try (InputStream in = CloseShieldInputStream.wrap(byteArrayInputStream)) {
69+
assertEquals(3, in.available());
70+
}
71+
}
72+
5573
@Test
5674
public void testClose() throws IOException {
5775
shielded = CloseShieldInputStream.wrap(byteArrayInputStream);
@@ -61,6 +79,17 @@ public void testClose() throws IOException {
6179
assertEquals(data[0], byteArrayInputStream.read(), "read()");
6280
}
6381

82+
83+
@Test
84+
public void testReadAfterCose() throws Exception {
85+
InputStream shadow;
86+
try (InputStream in = CloseShieldInputStream.wrap(byteArrayInputStream)) {
87+
assertEquals(3, in.available());
88+
shadow = in;
89+
}
90+
assertEquals(IOUtils.EOF, shadow.read());
91+
}
92+
6493
@Test
6594
public void testSystemInOnSystemInNo() throws IOException {
6695
shielded = CloseShieldInputStream.systemIn(byteArrayInputStream);

0 commit comments

Comments
 (0)