Skip to content

Commit a17cc99

Browse files
committed
Use Assertions
1 parent 8fa1c0e commit a17cc99

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.apache.commons.io.input.buffer;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2021
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
2123

2224
import java.io.ByteArrayInputStream;
2325
import java.io.IOException;
@@ -35,6 +37,10 @@ public class CircularBufferInputStreamTest {
3537
*/
3638
private final Random random = new Random(1530960934483L);
3739

40+
void asssertNotEof(int offset, final int res) {
41+
assertNotEquals(-1, res, () -> "Unexpected EOF at offset " + offset);
42+
}
43+
3844
/**
3945
* Create a large, but random input buffer.
4046
*/
@@ -71,33 +77,24 @@ public void testRandomRead() throws Exception {
7177
switch (random.nextInt(2)) {
7278
case 0: {
7379
final int res = cbis.read();
74-
if (res == -1) {
75-
throw new IllegalStateException("Unexpected EOF at offset " + offset);
76-
}
77-
if (inputBuffer[offset] != (byte) res) { // compare as bytes
78-
throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + res);
79-
}
80+
asssertNotEof(offset, res);
81+
// MUST compare bytes
82+
assertEquals(inputBuffer[offset], (byte) res, "Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + res);
8083
++offset;
8184
break;
8285
}
8386
case 1: {
8487
final int res = cbis.read(readBuffer, 0, random.nextInt(readBuffer.length + 1));
85-
if (res == -1) {
86-
throw new IllegalStateException("Unexpected EOF at offset " + offset);
87-
}
88-
if (res == 0) {
89-
throw new IllegalStateException("Unexpected zero-byte-result at offset " + offset);
90-
}
88+
asssertNotEof(offset, res);
89+
assertNotEquals(0, res, "Unexpected zero-byte-result at offset " + offset);
9190
for (int i = 0; i < res; i++) {
92-
if (inputBuffer[offset] != readBuffer[i]) {
93-
throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + readBuffer[i]);
94-
}
91+
assertEquals(inputBuffer[offset], readBuffer[i], "Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + readBuffer[i]);
9592
++offset;
9693
}
9794
break;
9895
}
9996
default:
100-
throw new IllegalStateException("Unexpected random choice value");
97+
fail("Unexpected random choice value");
10198
}
10299
}
103100
assertTrue(true, "Test finished OK");

0 commit comments

Comments
 (0)