garydgregory commented on code in PR #435:
URL: https://github.com/apache/commons-compress/pull/435#discussion_r1388194711
##########
src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java:
##########
@@ -68,4 +70,24 @@ public void
testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws IOExcept
}
}
+ @Test
+ public void testInvalidMaxCodeSize() throws IOException {
+ final File input = getFile("bla.tar.Z");
+ try (InputStream contentStream = Files.newInputStream(input.toPath()))
{
+ byte[] content = IOUtils.toByteArray(contentStream);
+
+ // Test all possible maxCodeSize values, it will either process
correctly, or throw an IOException
+ for (int maxCodeSize = Byte.MIN_VALUE; maxCodeSize <=
Byte.MAX_VALUE; maxCodeSize++) {
+ content[2] = (byte) maxCodeSize;
+ try {
+ final ZCompressorInputStream in = new
ZCompressorInputStream(new ByteArrayInputStream(content), 1024*1024);
+ IOUtils.toByteArray(in);
+ assertEquals(-1, in.read());
+ } catch(Exception e) {
+ assertInstanceOf(IOException.class, e);
Review Comment:
Hello @yakovsh
This is test is confusing: What is the expected behavior? What method call,
_exactly_, do you expect to throw `IOException`? The current test makes it look
like we expect _anything_ (the `ZCompressorInputStream` constructor, the call
to `toByteArray()`, or the call to `read()`) in the try block to throw
`IOException`, which surely is not what we want to assert. I imaging that you
care about the `read()` call. If so, use `assertThrow()` for that one call.
TY!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]