Skip to content

Commit

Permalink
add test for read() method
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Applin committed May 17, 2024
1 parent ca05f9a commit bceed61
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void noException_incorrectChecksum_shouldThrowCRC32Exception() {
InputStreamUtils.drainInputStream(is);

assertThatThrownBy(is::close).isInstanceOf(Crc32MismatchException.class);

}

@Test
Expand All @@ -68,6 +67,20 @@ void exceptionWhileReading_shouldNotValidateChecksum() {
assertThatCode(is::close).doesNotThrowAnyException();
}

@Test
void exception_readMethodCall_shouldNotValidateChecksum() {
Crc32ChecksumValidatingInputStream is = new Crc32ChecksumValidatingInputStream(
new FailAfterNInputStream(2, new IOException("test io exception")), 123);
assertThatThrownBy(() -> {
is.read();
is.read();
})
.isInstanceOf(IOException.class)
.hasMessageContaining("test io exception");

assertThatCode(is::close).doesNotThrowAnyException();
}

class FailAfterNInputStream extends InputStream {
private final int failAfter;
private final Random random;
Expand Down

0 comments on commit bceed61

Please sign in to comment.