This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit a17cc99de2f10874fc8b9b161d75781bca47dfbf Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Jul 14 18:11:55 2024 -0400 Use Assertions --- .../buffer/CircularBufferInputStreamTest.java | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java b/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java index 37e404d26..55d38f25c 100644 --- a/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java @@ -17,7 +17,9 @@ package org.apache.commons.io.input.buffer; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -35,6 +37,10 @@ public class CircularBufferInputStreamTest { */ private final Random random = new Random(1530960934483L); + void asssertNotEof(int offset, final int res) { + assertNotEquals(-1, res, () -> "Unexpected EOF at offset " + offset); + } + /** * Create a large, but random input buffer. */ @@ -71,33 +77,24 @@ public class CircularBufferInputStreamTest { switch (random.nextInt(2)) { case 0: { final int res = cbis.read(); - if (res == -1) { - throw new IllegalStateException("Unexpected EOF at offset " + offset); - } - if (inputBuffer[offset] != (byte) res) { // compare as bytes - throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + res); - } + asssertNotEof(offset, res); + // MUST compare bytes + assertEquals(inputBuffer[offset], (byte) res, "Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + res); ++offset; break; } case 1: { final int res = cbis.read(readBuffer, 0, random.nextInt(readBuffer.length + 1)); - if (res == -1) { - throw new IllegalStateException("Unexpected EOF at offset " + offset); - } - if (res == 0) { - throw new IllegalStateException("Unexpected zero-byte-result at offset " + offset); - } + asssertNotEof(offset, res); + assertNotEquals(0, res, "Unexpected zero-byte-result at offset " + offset); for (int i = 0; i < res; i++) { - if (inputBuffer[offset] != readBuffer[i]) { - throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + readBuffer[i]); - } + assertEquals(inputBuffer[offset], readBuffer[i], "Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + readBuffer[i]); ++offset; } break; } default: - throw new IllegalStateException("Unexpected random choice value"); + fail("Unexpected random choice value"); } } assertTrue(true, "Test finished OK");