1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io.input;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 import org.junit.jupiter.api.BeforeEach;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 public class CloseShieldInputStreamTest {
33
34 private byte[] data;
35
36 private InputStream original;
37
38 private InputStream shielded;
39
40 private boolean closed;
41
42 @BeforeEach
43 public void setUp() {
44 data = new byte[] { 'x', 'y', 'z' };
45 original = new ByteArrayInputStream(data) {
46 @Override
47 public void close() {
48 closed = true;
49 }
50 };
51 shielded = CloseShieldInputStream.wrap(original);
52 closed = false;
53 }
54
55 @Test
56 public void testClose() throws IOException {
57 shielded.close();
58 assertFalse(closed, "closed");
59 assertEquals(-1, shielded.read(), "read()");
60 assertEquals(data[0], original.read(), "read()");
61 }
62
63 }