garydgregory commented on code in PR #435:
URL: https://github.com/apache/commons-compress/pull/435#discussion_r1388488921
##########
src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java:
##########
@@ -68,4 +70,28 @@ public void
testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws IOExcept
}
}
+ @Test
+ public void testInvalidMaxCodeSize() throws IOException {
+ final File input = getFile("bla.tar.Z");
+ try (final InputStream contentStream =
Files.newInputStream(input.toPath())) {
+ final byte[] content = IOUtils.toByteArray(contentStream);
+
+ // Test all possible maxCodeSize values
+ for (int maxCodeSize = Byte.MIN_VALUE; maxCodeSize <=
Byte.MAX_VALUE; maxCodeSize++) {
+ content[2] = (byte) maxCodeSize;
+
+ // Test that no unexpected exceptions are thrown when
initializing and reading the stream,
+ // since maxCodeSize impacts both initialization and reading.
+ assertDoesNotThrow(() -> {
+ try {
+ final ZCompressorInputStream in =
+ new ZCompressorInputStream(new
ByteArrayInputStream(content), 1024*1024);
+ IOUtils.toByteArray(in);
+ } catch(IOException ignore) {
Review Comment:
Hello @yakovsh
The test is still too obtuse to maintain IMO:
- The test asserts that it does NOT throw, but
- Then it expects to catch an IOException and then ignores it
This is impossible for the mere mortal maintainer to understand.
The test would read better by testing which range of values are expected to
NOT throw, and, which range of values are expected to throw.
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]