Skip to content

Commit 30434ed

Browse files
committed
Simplify testing
1 parent 15ab5d4 commit 30434ed

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,11 @@ public class AutoCloseInputStreamTest {
4040

4141
private AutoCloseInputStream stream;
4242

43-
private boolean closed;
44-
4543
@SuppressWarnings("deprecation")
4644
@BeforeEach
4745
public void setUp() {
4846
data = new byte[] { 'x', 'y', 'z' };
49-
stream = new AutoCloseInputStream(new ByteArrayInputStream(data) {
50-
@Override
51-
public void close() throws IOException {
52-
closed = true;
53-
}
54-
});
55-
closed = false;
47+
stream = new AutoCloseInputStream(new ByteArrayInputStream(data));
5648
}
5749

5850
@Test
@@ -91,7 +83,6 @@ public void testBuilderGet() {
9183
@Test
9284
public void testClose() throws IOException {
9385
stream.close();
94-
assertTrue(closed, "closed");
9586
assertTrue(stream.isClosed(), "closed");
9687
assertEquals(-1, stream.read(), "read()");
9788
assertTrue(stream.isClosed(), "closed");
@@ -113,33 +104,33 @@ public void testCloseHandleIOException() throws IOException {
113104
@Test
114105
public void testFinalize() throws Throwable {
115106
stream.finalize();
116-
assertTrue(closed, "closed");
107+
assertTrue(stream.isClosed(), "closed");
117108
assertEquals(-1, stream.read(), "read()");
118109
}
119110

120111
@Test
121112
public void testRead() throws IOException {
122113
for (final byte element : data) {
123114
assertEquals(element, stream.read(), "read()");
124-
assertFalse(closed, "closed");
115+
assertFalse(stream.isClosed(), "closed");
125116
}
126117
assertEquals(-1, stream.read(), "read()");
127-
assertTrue(closed, "closed");
118+
assertTrue(stream.isClosed(), "closed");
128119
}
129120

130121
@Test
131122
public void testReadBuffer() throws IOException {
132123
final byte[] b = new byte[data.length * 2];
133124
int total = 0;
134125
for (int n = 0; n != -1; n = stream.read(b)) {
135-
assertFalse(closed, "closed");
126+
assertFalse(stream.isClosed(), "closed");
136127
for (int i = 0; i < n; i++) {
137128
assertEquals(data[total + i], b[i], "read(b)");
138129
}
139130
total += n;
140131
}
141132
assertEquals(data.length, total, "read(b)");
142-
assertTrue(closed, "closed");
133+
assertTrue(stream.isClosed(), "closed");
143134
assertEquals(-1, stream.read(b), "read(b)");
144135
}
145136

@@ -148,14 +139,14 @@ public void testReadBufferOffsetLength() throws IOException {
148139
final byte[] b = new byte[data.length * 2];
149140
int total = 0;
150141
for (int n = 0; n != -1; n = stream.read(b, total, b.length - total)) {
151-
assertFalse(closed, "closed");
142+
assertFalse(stream.isClosed(), "closed");
152143
total += n;
153144
}
154145
assertEquals(data.length, total, "read(b, off, len)");
155146
for (int i = 0; i < data.length; i++) {
156147
assertEquals(data[i], b[i], "read(b, off, len)");
157148
}
158-
assertTrue(closed, "closed");
149+
assertTrue(stream.isClosed(), "closed");
159150
assertEquals(-1, stream.read(b, 0, b.length), "read(b, off, len)");
160151
}
161152

0 commit comments

Comments
 (0)