Skip to content
Permalink
Browse files
Use assertThrows().
  • Loading branch information
garydgregory committed Dec 27, 2021
1 parent e5a4a4b commit 1d78f5bd8b1f86aaca702834086dd769bd84a50c
Showing 1 changed file with 3 additions and 13 deletions.
@@ -24,14 +24,14 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.apache.commons.compress.MemoryLimitException;
import org.apache.commons.compress.MockEvilInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
@@ -119,12 +119,7 @@ public void testDetection() throws Exception {
assertNotNull(zstd);
assertTrue(zstd instanceof ZstdCompressorInputStream);

try {
factory.createCompressorInputStream(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY));
fail("No exception thrown for an empty input stream");
} catch (final CompressorException e) {
// expected
}
assertThrows(CompressorException.class, () -> factory.createCompressorInputStream(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY)));
}

@Test
@@ -145,12 +140,7 @@ public void testDetect() throws Exception {
assertEquals(CompressorStreamFactory.Z, detect("COMPRESS-386"));
assertEquals(CompressorStreamFactory.LZMA, detect("COMPRESS-382"));

try {
CompressorStreamFactory.detect(new BufferedInputStream(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY)));
fail("shouldn't be able to detect empty stream");
} catch (final CompressorException e) {
assertEquals("No Compressor found for the stream signature.", e.getMessage());
}
assertThrows(CompressorException.class, () -> CompressorStreamFactory.detect(new BufferedInputStream(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY))));

try {
CompressorStreamFactory.detect(null);

0 comments on commit 1d78f5b

Please sign in to comment.