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-compress.git
The following commit(s) were added to refs/heads/master by this push: new f3a973ae Refactor test to new internal input stream factory f3a973ae is described below commit f3a973ae2534c5f5098d67bd17befe4f358c614d Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Feb 5 13:53:28 2023 -0500 Refactor test to new internal input stream factory --- .../apache/commons/compress/AbstractTestCase.java | 5 ++- .../apache/commons/compress/ChainingTestCase.java | 12 ++----- .../commons/compress/DetectArchiverTestCase.java | 3 +- .../archivers/ArchiveStreamFactoryTest.java | 28 +++++++--------- .../commons/compress/archivers/ZipTestCase.java | 2 +- .../archivers/ar/ArArchiveInputStreamTest.java | 13 ++++---- .../archivers/arj/ArjArchiveInputStreamTest.java | 11 +++---- .../archivers/cpio/CpioArchiveInputStreamTest.java | 11 +++---- .../archivers/dump/DumpArchiveInputStreamTest.java | 9 +++-- .../archivers/tar/TarArchiveInputStreamTest.java | 20 ++++++------ .../compress/archivers/tar/TarUtilsTest.java | 7 ++-- .../archivers/zip/Maven221MultiVolumeTest.java | 7 ++-- .../compress/archivers/zip/UTF8ZipFilesTest.java | 6 ++-- .../archivers/zip/ZipArchiveInputStreamTest.java | 38 +++++++++++----------- .../compress/archivers/zip/ZipFileTest.java | 13 ++++---- .../compress/changes/ChangeSetTestCase.java | 8 ++--- .../commons/compress/compressors/GZipTestCase.java | 4 +-- .../compress/compressors/Pack200TestCase.java | 8 ++--- .../bzip2/BZip2CompressorInputStreamTest.java | 6 ++-- .../lz4/BlockLZ4CompressorInputStreamTest.java | 4 +-- .../lz4/FramedLZ4CompressorInputStreamTest.java | 30 ++++++++--------- .../FramedSnappyCompressorInputStreamTest.java | 12 +++---- 22 files changed, 119 insertions(+), 138 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/AbstractTestCase.java b/src/test/java/org/apache/commons/compress/AbstractTestCase.java index cc60895e..69d98a39 100644 --- a/src/test/java/org/apache/commons/compress/AbstractTestCase.java +++ b/src/test/java/org/apache/commons/compress/AbstractTestCase.java @@ -239,9 +239,8 @@ public abstract class AbstractTestCase { */ protected void checkArchiveContent(final File archive, final List<String> expected) throws Exception { - try (InputStream is = Files.newInputStream(archive.toPath())) { - final BufferedInputStream buf = new BufferedInputStream(is); - final ArchiveInputStream in = factory.createArchiveInputStream(buf); + try (InputStream is = Files.newInputStream(archive.toPath()); + final ArchiveInputStream in = factory.createArchiveInputStream(new BufferedInputStream(is))) { this.checkArchiveContent(in, expected); } } diff --git a/src/test/java/org/apache/commons/compress/ChainingTestCase.java b/src/test/java/org/apache/commons/compress/ChainingTestCase.java index a9abeddf..d984559a 100644 --- a/src/test/java/org/apache/commons/compress/ChainingTestCase.java +++ b/src/test/java/org/apache/commons/compress/ChainingTestCase.java @@ -21,23 +21,17 @@ package org.apache.commons.compress; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.io.File; -import java.nio.file.Files; - import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.junit.jupiter.api.Test; - public class ChainingTestCase extends AbstractTestCase { @Test public void testTarBzip2() throws Exception { - final File file = getFile("bla.tar.bz2"); - try (final TarArchiveInputStream is = new TarArchiveInputStream( - new BZip2CompressorInputStream(Files.newInputStream(file.toPath())))) { + try (final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(newInputStream("bla.tar.bz2")))) { final TarArchiveEntry entry = (TarArchiveEntry) is.getNextEntry(); assertNotNull(entry); assertEquals("test1.xml", entry.getName()); @@ -46,9 +40,7 @@ public class ChainingTestCase extends AbstractTestCase { @Test public void testTarGzip() throws Exception { - final File file = getFile("bla.tgz"); - try (final TarArchiveInputStream is = new TarArchiveInputStream( - new GzipCompressorInputStream(Files.newInputStream(file.toPath())))) { + try (final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(newInputStream("bla.tgz")))) { final TarArchiveEntry entry = (TarArchiveEntry) is.getNextEntry(); assertNotNull(entry); assertEquals("test1.xml", entry.getName()); diff --git a/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java b/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java index 118b2245..8b373eb6 100644 --- a/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java +++ b/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java @@ -53,8 +53,7 @@ public final class DetectArchiverTestCase extends AbstractTestCase { private ArchiveInputStream getStreamFor(final String resource) throws ArchiveException, IOException { - return factory.createArchiveInputStream( - new BufferedInputStream(Files.newInputStream(getFile(resource).toPath()))); + return factory.createArchiveInputStream(new BufferedInputStream(newInputStream(resource))); } @Test diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java index 536627e1..409d310d 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java @@ -18,7 +18,6 @@ */ package org.apache.commons.compress.archivers; -import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -28,12 +27,11 @@ import static org.junit.jupiter.api.Assertions.fail; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; -import java.nio.file.Files; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.MockEvilInputStream; import org.apache.commons.compress.archivers.arj.ArjArchiveInputStream; import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream; @@ -44,7 +42,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.apache.commons.compress.utils.ByteUtils; import org.junit.jupiter.api.Test; -public class ArchiveStreamFactoryTest { +public class ArchiveStreamFactoryTest extends AbstractTestCase { static class TestData { final String testFile; @@ -99,14 +97,14 @@ public class ArchiveStreamFactoryTest { String dflt; dflt = UNKNOWN; try { - dflt = getField(new ArjArchiveInputStream(Files.newInputStream(getFile("bla.arj").toPath())), "charsetName"); + dflt = getField(new ArjArchiveInputStream(newInputStream("bla.arj")), "charsetName"); } catch (final Exception e) { e.printStackTrace(); } ARJ_DEFAULT = dflt; dflt = UNKNOWN; try { - dflt = getField(new DumpArchiveInputStream(Files.newInputStream(getFile("bla.dump").toPath())), "encoding"); + dflt = getField(new DumpArchiveInputStream(newInputStream("bla.dump")), "encoding"); } catch (final Exception e) { e.printStackTrace(); } @@ -201,7 +199,7 @@ public class ArchiveStreamFactoryTest { */ @Test public void aiffFilesAreNoTARs() throws Exception { - try (final InputStream fis = Files.newInputStream(new File("src/test/resources/testAIFF.aif").toPath()); + try (final InputStream fis = newInputStream("testAIFF.aif"); final InputStream is = new BufferedInputStream(fis)) { final ArchiveException ae = assertThrows(ArchiveException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(is), "created an input stream for a non-archive"); @@ -219,8 +217,9 @@ public class ArchiveStreamFactoryTest { assertThrows(StreamingNotSupportedException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.SEVEN_Z, new ByteArrayOutputStream())); } + private String detect(final String resource) throws IOException, ArchiveException { - try(InputStream in = new BufferedInputStream(Files.newInputStream(getFile(resource).toPath()))) { + try (InputStream in = new BufferedInputStream(newInputStream(resource))) { return ArchiveStreamFactory.detect(in); } } @@ -231,7 +230,7 @@ public class ArchiveStreamFactoryTest { */ @Test public void detectsAndThrowsFor7z() throws Exception { - try (final InputStream fis = Files.newInputStream(new File("src/test/resources/bla.7z").toPath()); + try (final InputStream fis = newInputStream("bla.7z"); final InputStream bis = new BufferedInputStream(fis)) { final StreamingNotSupportedException ex = assertThrows(StreamingNotSupportedException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis), "Expected a StreamingNotSupportedException"); @@ -241,15 +240,12 @@ public class ArchiveStreamFactoryTest { private ArchiveInputStream getInputStreamFor(final String resource, final ArchiveStreamFactory factory) throws IOException, ArchiveException { - return factory.createArchiveInputStream( - new BufferedInputStream(Files.newInputStream(getFile(resource).toPath()))); + return factory.createArchiveInputStream(new BufferedInputStream(newInputStream(resource))); } private ArchiveInputStream getInputStreamFor(final String type, final String resource, final ArchiveStreamFactory factory) throws IOException, ArchiveException { - return factory.createArchiveInputStream( - type, - new BufferedInputStream(Files.newInputStream(getFile(resource).toPath()))); + return factory.createArchiveInputStream(type, new BufferedInputStream(newInputStream(resource))); } private ArchiveOutputStream getOutputStreamFor(final String type, final ArchiveStreamFactory factory) @@ -274,7 +270,7 @@ public class ArchiveStreamFactoryTest { */ @Test public void skipsPK00Prefix() throws Exception { - try (InputStream fis = Files.newInputStream(new File("src/test/resources/COMPRESS-208.zip").toPath())) { + try (InputStream fis = newInputStream("COMPRESS-208.zip")) { try (InputStream bis = new BufferedInputStream(fis)) { try (ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis)) { assertTrue(ais instanceof ZipArchiveInputStream); @@ -285,7 +281,7 @@ public class ArchiveStreamFactoryTest { @Test public void testCOMPRESS209() throws Exception { - try (final InputStream fis = Files.newInputStream(new File("src/test/resources/testCompress209.doc").toPath()); + try (final InputStream fis = newInputStream("testCompress209.doc"); final InputStream bis = new BufferedInputStream(fis)) { final ArchiveException ae = assertThrows(ArchiveException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis), "created an input stream for a non-archive"); diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java index 7453019b..beba97dc 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java +++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java @@ -654,7 +654,7 @@ public final class ZipTestCase extends AbstractTestCase { @Test public void testSkipEntryWithUnsupportedCompressionMethod() throws IOException { - try (ZipArchiveInputStream zip = new ZipArchiveInputStream(Files.newInputStream(getFile("moby.zip").toPath()))) { + try (ZipArchiveInputStream zip = new ZipArchiveInputStream(newInputStream("moby.zip"))) { final ZipArchiveEntry entry = zip.getNextZipEntry(); assertEquals(ZipMethod.TOKENIZATION.getCode(), entry.getMethod(), "method"); assertEquals("README", entry.getName()); diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java index 5692b92a..8077a5fd 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java @@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; @@ -41,7 +40,7 @@ public class ArArchiveInputStreamTest extends AbstractTestCase { @Test public void cantReadAfterClose() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.ar").toPath()); + try (InputStream in = newInputStream("bla.ar"); ArArchiveInputStream archive = new ArArchiveInputStream(in)) { archive.close(); assertThrows(IllegalStateException.class, () -> archive.read()); @@ -50,14 +49,14 @@ public class ArArchiveInputStreamTest extends AbstractTestCase { @Test public void cantReadWithoutOpeningAnEntry() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.ar").toPath()); + try (InputStream in = newInputStream("bla.ar"); ArArchiveInputStream archive = new ArArchiveInputStream(in)) { assertThrows(IllegalStateException.class, () -> archive.read()); } } private void checkLongNameEntry(final String archive) throws Exception { - try (final InputStream fis = Files.newInputStream((getFile(archive).toPath())); + try (final InputStream fis = newInputStream(archive); final ArArchiveInputStream s = new ArArchiveInputStream(new BufferedInputStream(fis))) { ArchiveEntry e = s.getNextEntry(); assertEquals("this_is_a_long_file_name.txt", e.getName()); @@ -78,7 +77,7 @@ public class ArArchiveInputStreamTest extends AbstractTestCase { @Test public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { final byte[] buf = new byte[2]; - try (InputStream in = Files.newInputStream(getFile("bla.ar").toPath()); + try (InputStream in = newInputStream("bla.ar"); ArArchiveInputStream archive = new ArArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -89,7 +88,7 @@ public class ArArchiveInputStreamTest extends AbstractTestCase { @Test public void simpleInputStream() throws IOException { - try (final InputStream fileInputStream = Files.newInputStream(getFile("bla.ar").toPath())) { + try (final InputStream fileInputStream = newInputStream("bla.ar")) { // This default implementation of InputStream.available() always returns zero, // and there are many streams in practice where the total length of the stream is not known. @@ -118,7 +117,7 @@ public class ArArchiveInputStreamTest extends AbstractTestCase { @Test public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.ar").toPath()); + try (InputStream in = newInputStream("bla.ar"); ArArchiveInputStream archive = new ArArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); diff --git a/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java index 59c1100c..39be43f2 100644 --- a/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.InputStream; -import java.nio.file.Files; import java.util.Calendar; import java.util.TimeZone; @@ -37,7 +36,7 @@ public class ArjArchiveInputStreamTest extends AbstractTestCase { @Test public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { final byte[] buf = new byte[2]; - try (InputStream in = Files.newInputStream(getFile("bla.arj").toPath()); + try (InputStream in = newInputStream("bla.arj"); ArjArchiveInputStream archive = new ArjArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -48,7 +47,7 @@ public class ArjArchiveInputStreamTest extends AbstractTestCase { @Test public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.arj").toPath()); + try (InputStream in = newInputStream("bla.arj"); ArjArchiveInputStream archive = new ArjArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -65,7 +64,7 @@ public class ArjArchiveInputStreamTest extends AbstractTestCase { expected.append("<empty/>\n"); final StringBuilder result = new StringBuilder(); - try (final ArjArchiveInputStream in = new ArjArchiveInputStream(Files.newInputStream(getFile("bla.arj").toPath()))) { + try (final ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.arj"))) { ArjArchiveEntry entry; while ((entry = in.getNextEntry()) != null) { @@ -82,7 +81,7 @@ public class ArjArchiveInputStreamTest extends AbstractTestCase { @Test public void testReadingOfAttributesDosVersion() throws Exception { - try (final ArjArchiveInputStream in = new ArjArchiveInputStream(Files.newInputStream(getFile("bla.arj").toPath()))) { + try (final ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.arj"))) { final ArjArchiveEntry entry = in.getNextEntry(); assertEquals("test1.xml", entry.getName()); assertEquals(30, entry.getSize()); @@ -96,7 +95,7 @@ public class ArjArchiveInputStreamTest extends AbstractTestCase { @Test public void testReadingOfAttributesUnixVersion() throws Exception { - try (final ArjArchiveInputStream in = new ArjArchiveInputStream(Files.newInputStream(getFile("bla.unix.arj").toPath()))) { + try (final ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.unix.arj"))) { final ArjArchiveEntry entry = in.getNextEntry(); assertEquals("test1.xml", entry.getName()); assertEquals(30, entry.getSize()); diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java index 61ea76be..ac2ae26c 100644 --- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.InputStream; -import java.nio.file.Files; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; @@ -34,7 +33,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase { @Test public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { final byte[] buf = new byte[2]; - try (InputStream in = Files.newInputStream(getFile("bla.cpio").toPath()); CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) { + try (InputStream in = newInputStream("bla.cpio"); CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); assertEquals(-1, archive.read(buf)); @@ -44,7 +43,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase { @Test public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.cpio").toPath()); CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) { + try (InputStream in = newInputStream("bla.cpio"); CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); assertEquals(-1, archive.read()); @@ -60,7 +59,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase { expected.append("<empty/>\n"); final StringBuilder result = new StringBuilder(); - try (final CpioArchiveInputStream in = new CpioArchiveInputStream(Files.newInputStream(getFile("bla.cpio").toPath()))) { + try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("bla.cpio"))) { CpioArchiveEntry entry; while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) { @@ -77,7 +76,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase { @Test public void testCpioUnarchiveCreatedByRedlineRpm() throws Exception { int count = 0; - try (final CpioArchiveInputStream in = new CpioArchiveInputStream(Files.newInputStream(getFile("redline.cpio").toPath()))) { + try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("redline.cpio"))) { CpioArchiveEntry entry = null; while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) { @@ -92,7 +91,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase { @Test public void testCpioUnarchiveMultibyteCharName() throws Exception { int count = 0; - try (final CpioArchiveInputStream in = new CpioArchiveInputStream(Files.newInputStream(getFile("COMPRESS-459.cpio").toPath()), "UTF-8")) { + try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("COMPRESS-459.cpio"), "UTF-8")) { CpioArchiveEntry entry = null; while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) { diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java index 201d6993..61f2ca3d 100644 --- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java @@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.InputStream; -import java.nio.file.Files; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; @@ -38,7 +37,7 @@ public class DumpArchiveInputStreamTest extends AbstractTestCase { @Test public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { final byte[] buf = new byte[2]; - try (InputStream in = Files.newInputStream(getFile("bla.dump").toPath()); + try (InputStream in = newInputStream("bla.dump"); DumpArchiveInputStream archive = new DumpArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -49,7 +48,7 @@ public class DumpArchiveInputStreamTest extends AbstractTestCase { @Test public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.dump").toPath()); + try (InputStream in = newInputStream("bla.dump"); DumpArchiveInputStream archive = new DumpArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -77,7 +76,7 @@ public class DumpArchiveInputStreamTest extends AbstractTestCase { @Test public void testNotADumpArchive() throws Exception { - try (InputStream is = Files.newInputStream(getFile("bla.zip").toPath())) { + try (InputStream is = newInputStream("bla.zip")) { final ArchiveException ex = assertThrows(ArchiveException.class, () -> new DumpArchiveInputStream(is).close(), "expected an exception"); assertTrue(ex.getCause() instanceof ShortFileException); @@ -86,7 +85,7 @@ public class DumpArchiveInputStreamTest extends AbstractTestCase { @Test public void testNotADumpArchiveButBigEnough() throws Exception { - try (InputStream is = Files.newInputStream(getFile("zip64support.tar.bz2").toPath())) { + try (InputStream is = newInputStream("zip64support.tar.bz2")) { final ArchiveException ex = assertThrows(ArchiveException.class, () -> new DumpArchiveInputStream(is).close(), "expected an exception"); assertInstanceOf(UnrecognizedFormatException.class, ex.getCause()); diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index 2494aa9b..9bef09e3 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -89,7 +89,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { final byte[] buf = new byte[2]; - try (InputStream in = Files.newInputStream(getFile("bla.tar").toPath()); + try (InputStream in = newInputStream("bla.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -118,7 +118,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void rejectsArchivesWithNegativeSizes() throws Exception { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-569.tar").toPath()); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { + try (InputStream in = newInputStream("COMPRESS-569.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { getNextEntryUntilIOException(archive); } } @@ -218,7 +218,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { } @Test public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.tar").toPath()); + try (InputStream in = newInputStream("bla.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -373,7 +373,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void testParseTarTruncatedInContent() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-544_truncated_in_content.tar").toPath()); + try (InputStream in = newInputStream("COMPRESS-544_truncated_in_content.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { getNextEntryUntilIOException(archive); } @@ -381,7 +381,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void testParseTarTruncatedInPadding() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-544_truncated_in_padding.tar").toPath()); + try (InputStream in = newInputStream("COMPRESS-544_truncated_in_padding.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { getNextEntryUntilIOException(archive); } @@ -389,14 +389,14 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void testParseTarWithNonNumberPaxHeaders() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-529.tar").toPath()); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { + try (InputStream in = newInputStream("COMPRESS-529.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { assertThrows(IOException.class, () -> archive.getNextEntry()); } } @Test public void testParseTarWithSpecialPaxHeaders() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-530.tar").toPath()); + try (InputStream in = newInputStream("COMPRESS-530.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { assertThrows(IOException.class, () -> archive.getNextEntry()); assertThrows(IOException.class, () -> IOUtils.toByteArray(archive)); @@ -405,7 +405,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void testThrowException() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-553.tar").toPath()); + try (InputStream in = newInputStream("COMPRESS-553.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { getNextEntryUntilIOException(archive); } @@ -413,7 +413,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void testThrowExceptionWithNullEntry() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-554.tar").toPath()); + try (InputStream in = newInputStream("COMPRESS-554.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { getNextEntryUntilIOException(archive); } @@ -421,7 +421,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test public void workaroundForBrokenTimeHeader() throws Exception { - try (TarArchiveInputStream in = new TarArchiveInputStream(Files.newInputStream(getFile("simple-aix-native-tar.tar").toPath()))) { + try (TarArchiveInputStream in = new TarArchiveInputStream(newInputStream("simple-aix-native-tar.tar"))) { TarArchiveEntry tae = in.getNextTarEntry(); tae = in.getNextTarEntry(); assertEquals("sample/link-to-txt-file.lnk", tae.getName()); diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java index 2cf054c1..b316b952 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java @@ -19,7 +19,6 @@ package org.apache.commons.compress.archivers.tar; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -29,20 +28,20 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; -import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.zip.ZipEncoding; import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; import org.apache.commons.compress.utils.ByteUtils; import org.apache.commons.compress.utils.CharsetNames; import org.junit.jupiter.api.Test; -public class TarUtilsTest { +public class TarUtilsTest extends AbstractTestCase { private void checkName(final String string) { final byte[] buff = new byte[100]; @@ -496,7 +495,7 @@ public class TarUtilsTest { @Test public void testParseTarWithSpecialPaxHeaders() throws IOException { - try (InputStream in = Files.newInputStream(getFile("COMPRESS-530.tar").toPath()); + try (InputStream in = newInputStream("COMPRESS-530.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { assertThrows(IOException.class, () -> archive.getNextEntry()); // IOUtils.toByteArray(archive); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java index bd26ad20..b2d20817 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java @@ -18,14 +18,13 @@ package org.apache.commons.compress.archivers.zip; -import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; import org.junit.jupiter.api.Test; @@ -43,7 +42,7 @@ import org.junit.jupiter.api.Test; * yields an exception. * */ -public class Maven221MultiVolumeTest { +public class Maven221MultiVolumeTest extends AbstractTestCase { private static final String[] ENTRIES = { // @formatter:off @@ -76,7 +75,7 @@ public class Maven221MultiVolumeTest { @Test public void testRead7ZipMultiVolumeArchiveForStream() throws IOException { - try (final InputStream archive = Files.newInputStream(getFile("apache-maven-2.2.1.zip.001").toPath()); + try (final InputStream archive = newInputStream("apache-maven-2.2.1.zip.001"); ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, null, false)) { // these are the entries that are supposed to be processed diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java index 2ec3cecf..c5069fe3 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java @@ -216,7 +216,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { */ @Test public void streamSkipsOverUnicodeExtraFieldWithUnsupportedVersion() throws IOException { - try (InputStream archive = Files.newInputStream(getFile("COMPRESS-479.zip").toPath()); + try (InputStream archive = newInputStream("COMPRESS-479.zip"); ZipArchiveInputStream zi = new ZipArchiveInputStream(archive)) { assertEquals(OIL_BARREL_TXT, zi.getNextEntry().getName()); assertEquals("%U20AC_for_Dollar.txt", zi.getNextEntry().getName()); @@ -252,7 +252,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { public void testRawNameReadFromStream() throws IOException { final InputStream archive = - Files.newInputStream(getFile("utf8-7zip-test.zip").toPath()); + newInputStream("utf8-7zip-test.zip"); try (ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, CP437, false)) { assertRawNameOfAcsiiTxt((ZipArchiveEntry) zi.getNextEntry()); } @@ -294,7 +294,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { @Test public void testRead7ZipArchiveForStream() throws IOException { final InputStream archive = - Files.newInputStream(getFile("utf8-7zip-test.zip").toPath()); + newInputStream("utf8-7zip-test.zip"); try (ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, CP437, false)) { assertEquals(ASCII_TXT, zi.getNextEntry().getName()); assertEquals(OIL_BARREL_TXT, zi.getNextEntry().getName()); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java index ef8357e9..ca089e9e 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java @@ -18,7 +18,6 @@ package org.apache.commons.compress.archivers.zip; -import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -42,6 +41,7 @@ import java.util.Arrays; import java.util.zip.ZipEntry; import java.util.zip.ZipException; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; @@ -49,7 +49,7 @@ import org.apache.commons.compress.utils.ByteUtils; import org.apache.commons.compress.utils.IOUtils; import org.junit.jupiter.api.Test; -public class ZipArchiveInputStreamTest { +public class ZipArchiveInputStreamTest extends AbstractTestCase { private static void nameSource(final String archive, final String entry, int entryNo, final ZipArchiveEntry.NameSource expected) throws Exception { @@ -147,7 +147,7 @@ public class ZipArchiveInputStreamTest { private void multiByteReadConsistentlyReturnsMinusOneAtEof(final File file) throws Exception { final byte[] buf = new byte[2]; - try (InputStream in = Files.newInputStream(getFile("bla.zip").toPath()); + try (InputStream in = newInputStream("bla.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(in)) { final ArchiveEntry e = archive.getNextEntry(); IOUtils.toByteArray(archive); @@ -239,7 +239,7 @@ public class ZipArchiveInputStreamTest { @Test public void properlyReadsStoredEntries() throws IOException { - try (InputStream fs = Files.newInputStream(getFile("bla-stored.zip").toPath()); + try (InputStream fs = newInputStream("bla-stored.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs)) { ZipArchiveEntry e = archive.getNextZipEntry(); assertNotNull(e); @@ -261,7 +261,7 @@ public class ZipArchiveInputStreamTest { @Test public void properlyReadsStoredEntryWithDataDescriptorWithoutSignature() throws IOException { - try (InputStream fs = Files.newInputStream(getFile("bla-stored-dd-nosig.zip").toPath()); + try (InputStream fs = newInputStream("bla-stored-dd-nosig.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { final ZipArchiveEntry e = archive.getNextZipEntry(); assertNotNull(e); @@ -277,7 +277,7 @@ public class ZipArchiveInputStreamTest { @Test public void properlyReadsStoredEntryWithDataDescriptorWithSignature() throws IOException { - try (InputStream fs = Files.newInputStream(getFile("bla-stored-dd.zip").toPath()); + try (InputStream fs = newInputStream("bla-stored-dd.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { final ZipArchiveEntry e = archive.getNextZipEntry(); assertNotNull(e); @@ -355,7 +355,7 @@ public class ZipArchiveInputStreamTest { @Test public void rejectsStoredEntriesWithDataDescriptorByDefault() throws IOException { - try (InputStream fs = Files.newInputStream(getFile("bla-stored-dd.zip").toPath()); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs)) { + try (InputStream fs = newInputStream("bla-stored-dd.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs)) { final ZipArchiveEntry e = archive.getNextZipEntry(); assertNotNull(e); assertEquals("test1.xml", e.getName()); @@ -385,7 +385,7 @@ public class ZipArchiveInputStreamTest { */ @Test public void shouldReadNestedZip() throws IOException { - try (ZipArchiveInputStream in = new ZipArchiveInputStream(Files.newInputStream(getFile("COMPRESS-219.zip").toPath()))) { + try (ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("COMPRESS-219.zip"))) { extractZipInputStream(in); } } @@ -456,7 +456,7 @@ public class ZipArchiveInputStreamTest { */ @Test public void testMessageWithCorruptFileName() throws Exception { - try (ZipArchiveInputStream in = new ZipArchiveInputStream(Files.newInputStream(getFile("COMPRESS-351.zip").toPath()))) { + try (ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("COMPRESS-351.zip"))) { final EOFException ex = assertThrows(EOFException.class, () -> { ZipArchiveEntry ze = in.getNextZipEntry(); while (ze != null) { @@ -497,7 +497,7 @@ public class ZipArchiveInputStreamTest { @Test public void testReadingOfFirstStoredEntry() throws Exception { - try (ZipArchiveInputStream in = new ZipArchiveInputStream(Files.newInputStream(getFile("COMPRESS-264.zip").toPath()))) { + try (ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("COMPRESS-264.zip"))) { final ZipArchiveEntry ze = in.getNextZipEntry(); assertEquals(5, ze.getSize()); assertArrayEquals(new byte[] { 'd', 'a', 't', 'a', '\n' }, @@ -602,13 +602,13 @@ public class ZipArchiveInputStreamTest { @Test public void testUnshrinkEntry() throws Exception { - final ZipArchiveInputStream in = new ZipArchiveInputStream(Files.newInputStream(getFile("SHRUNK.ZIP").toPath())); + final ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("SHRUNK.ZIP")); ZipArchiveEntry entry = in.getNextZipEntry(); assertEquals(ZipMethod.UNSHRINKING.getCode(), entry.getMethod(), "method"); assertTrue(in.canReadEntryData(entry)); - InputStream original = Files.newInputStream(getFile("test1.xml").toPath()); + InputStream original = newInputStream("test1.xml"); try { assertArrayEquals(IOUtils.toByteArray(original), IOUtils.toByteArray(in)); } finally { @@ -619,7 +619,7 @@ public class ZipArchiveInputStreamTest { assertEquals(ZipMethod.UNSHRINKING.getCode(), entry.getMethod(), "method"); assertTrue(in.canReadEntryData(entry)); - original = Files.newInputStream(getFile("test2.xml").toPath()); + original = newInputStream("test2.xml"); try { assertArrayEquals(IOUtils.toByteArray(original), IOUtils.toByteArray(in)); } finally { @@ -630,7 +630,7 @@ public class ZipArchiveInputStreamTest { @Test public void testUnzipBZip2CompressedEntry() throws Exception { - try (ZipArchiveInputStream in = new ZipArchiveInputStream(Files.newInputStream(getFile("bzip2-zip.zip").toPath()))) { + try (ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("bzip2-zip.zip"))) { final ZipArchiveEntry ze = in.getNextZipEntry(); assertEquals(42, ze.getSize()); final byte[] expected = new byte[42]; @@ -672,7 +672,7 @@ public class ZipArchiveInputStreamTest { @Test public void testZipWithBadExtraFields() throws IOException { - try (InputStream fis = Files.newInputStream(getFile("COMPRESS-548.zip").toPath()); + try (InputStream fis = newInputStream("COMPRESS-548.zip"); ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis)) { getAllZipEntries(zipInputStream); } @@ -680,7 +680,7 @@ public class ZipArchiveInputStreamTest { @Test public void throwsIfStoredDDIsDifferentFromLengthRead() throws IOException { - try (InputStream fs = Files.newInputStream(getFile("bla-stored-dd-contradicts-actualsize.zip").toPath()); + try (InputStream fs = newInputStream("bla-stored-dd-contradicts-actualsize.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { final ZipArchiveEntry e = archive.getNextZipEntry(); assertNotNull(e); @@ -693,7 +693,7 @@ public class ZipArchiveInputStreamTest { @Test public void throwsIfStoredDDIsInconsistent() throws IOException { - try (InputStream fs = Files.newInputStream(getFile("bla-stored-dd-sizes-differ.zip").toPath()); + try (InputStream fs = newInputStream("bla-stored-dd-sizes-differ.zip"); ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { final ZipArchiveEntry e = archive.getNextZipEntry(); assertNotNull(e); @@ -735,7 +735,7 @@ public class ZipArchiveInputStreamTest { @Test public void throwsIOExceptionIfThereIsCorruptedZip64Extra() throws IOException { - try (InputStream fis = Files.newInputStream(getFile("COMPRESS-546.zip").toPath()); + try (InputStream fis = newInputStream("COMPRESS-546.zip"); ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis)) { assertThrows(IOException.class, () -> getAllZipEntries(zipInputStream)); } @@ -746,7 +746,7 @@ public class ZipArchiveInputStreamTest { */ @Test public void winzipBackSlashWorkaround() throws Exception { - try (ZipArchiveInputStream in = new ZipArchiveInputStream(Files.newInputStream(getFile("test-winzip.zip").toPath()))) { + try (ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("test-winzip.zip"))) { ZipArchiveEntry zae = in.getNextZipEntry(); zae = in.getNextZipEntry(); zae = in.getNextZipEntry(); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java index 2e6d35ec..3314b5eb 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java @@ -19,7 +19,6 @@ package org.apache.commons.compress.archivers.zip; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -53,6 +52,7 @@ import java.util.zip.CRC32; import java.util.zip.Deflater; import java.util.zip.ZipEntry; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.utils.ByteUtils; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; @@ -60,7 +60,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; -public class ZipFileTest { +public class ZipFileTest extends AbstractTestCase { + private static void assertEntryName(final ArrayList<ZipArchiveEntry> entries, final int index, final String expectedName) { @@ -394,7 +395,7 @@ public class ZipFileTest { @Test public void testCDOrderInMemory() throws Exception { byte[] data = null; - try (InputStream fis = Files.newInputStream(getFile("ordertest.zip").toPath())) { + try (InputStream fis = newInputStream("ordertest.zip")) { data = IOUtils.toByteArray(fis); } @@ -460,7 +461,7 @@ public class ZipFileTest { public void testConcurrentReadSeekable() throws Exception { // mixed.zip contains both inflated and stored files byte[] data = null; - try (InputStream fis = Files.newInputStream(getFile("mixed.zip").toPath())) { + try (InputStream fis = newInputStream("mixed.zip")) { data = IOUtils.toByteArray(fis); } try (final SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(data)) { @@ -944,12 +945,12 @@ public class ZipFileTest { public void testUnshrinking() throws Exception { zf = new ZipFile(getFile("SHRUNK.ZIP")); ZipArchiveEntry test = zf.getEntry("TEST1.XML"); - try (InputStream original = Files.newInputStream(getFile("test1.xml").toPath()); + try (InputStream original = newInputStream("test1.xml"); InputStream inputStream = zf.getInputStream(test)) { assertArrayEquals(IOUtils.toByteArray(original), IOUtils.toByteArray(inputStream)); } test = zf.getEntry("TEST2.XML"); - try (InputStream original = Files.newInputStream(getFile("test2.xml").toPath()); + try (InputStream original = newInputStream("test2.xml"); InputStream inputStream = zf.getInputStream(test)) { assertArrayEquals(IOUtils.toByteArray(original), IOUtils.toByteArray(inputStream)); } diff --git a/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java b/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java index d926c177..f81efa49 100644 --- a/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java +++ b/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java @@ -132,8 +132,8 @@ public final class ChangeSetTestCase extends AbstractTestCase { */ @Test public void testAddChangeTwice() throws Exception { - try (InputStream in = Files.newInputStream(getFile("test.txt").toPath()); - InputStream in2 = Files.newInputStream(getFile("test2.xml").toPath())) { + try (InputStream in = newInputStream("test.txt"); + InputStream in2 = newInputStream("test2.xml")) { final ArchiveEntry e = new ZipArchiveEntry("test.txt"); final ArchiveEntry e2 = new ZipArchiveEntry("test.txt"); @@ -157,8 +157,8 @@ public final class ChangeSetTestCase extends AbstractTestCase { */ @Test public void testAddChangeTwiceWithoutReplace() throws Exception { - try (InputStream in = Files.newInputStream(getFile("test.txt").toPath()); - InputStream in2 = Files.newInputStream(getFile("test2.xml").toPath())) { + try (InputStream in = newInputStream("test.txt"); + InputStream in2 = newInputStream("test2.xml")) { final ArchiveEntry e = new ZipArchiveEntry("test.txt"); final ArchiveEntry e2 = new ZipArchiveEntry("test.txt"); diff --git a/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java b/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java index 43254a26..83bcfb8c 100644 --- a/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java +++ b/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java @@ -164,7 +164,7 @@ public final class GZipTestCase extends AbstractTestCase { @Test public void testInteroperabilityWithGzipCompressorInputStream() throws Exception { final byte[] content; - try (InputStream fis = Files.newInputStream(getFile("test3.xml").toPath())) { + try (InputStream fis = newInputStream("test3.xml")) { content = IOUtils.toByteArray(fis); } @@ -190,7 +190,7 @@ public final class GZipTestCase extends AbstractTestCase { @Test public void testInteroperabilityWithGZIPInputStream() throws Exception { final byte[] content; - try (InputStream fis = Files.newInputStream(getFile("test3.xml").toPath())) { + try (InputStream fis = newInputStream("test3.xml")) { content = IOUtils.toByteArray(fis); } diff --git a/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java b/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java index 2e9a82aa..f5f695c7 100644 --- a/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java +++ b/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java @@ -136,7 +136,7 @@ public final class Pack200TestCase extends AbstractTestCase { @Test public void testBadSignature() throws Exception { - try (InputStream is = Files.newInputStream(getFile("bla.jar").toPath())) { + try (InputStream is = newInputStream("bla.jar")) { final byte[] sig = new byte[4]; is.read(sig); assertFalse(Pack200CompressorInputStream.matches(sig, 4)); @@ -145,7 +145,7 @@ public final class Pack200TestCase extends AbstractTestCase { @Test public void testGoodSignature() throws Exception { - try (InputStream is = Files.newInputStream(getFile("bla.pack").toPath())) { + try (InputStream is = newInputStream("bla.pack")) { final byte[] sig = new byte[4]; is.read(sig); assertTrue(Pack200CompressorInputStream.matches(sig, 4)); @@ -156,7 +156,7 @@ public final class Pack200TestCase extends AbstractTestCase { public void testInputStreamMethods() throws Exception { final Map<String, String> m = new HashMap<>(); m.put("foo", "bar"); - try (InputStream is = new Pack200CompressorInputStream(Files.newInputStream(getFile("bla.jar").toPath()), + try (InputStream is = new Pack200CompressorInputStream(newInputStream("bla.jar"), m)) { // packed file is a jar, which is a ZIP so it starts with // a local file header @@ -219,7 +219,7 @@ public final class Pack200TestCase extends AbstractTestCase { @Test public void testShortSignature() throws Exception { - try (InputStream is = Files.newInputStream(getFile("bla.pack").toPath())) { + try (InputStream is = newInputStream("bla.pack")) { final byte[] sig = new byte[2]; is.read(sig); assertFalse(Pack200CompressorInputStream.matches(sig, 2)); diff --git a/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java index 0ca2852c..7c32c828 100644 --- a/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java @@ -18,7 +18,6 @@ */ package org.apache.commons.compress.compressors.bzip2; -import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -29,13 +28,14 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.utils.IOUtils; import org.junit.jupiter.api.Test; -public class BZip2CompressorInputStreamTest { +public class BZip2CompressorInputStreamTest extends AbstractTestCase { private void fuzzingTest(final int[] bytes) throws IOException, ArchiveException { final int len = bytes.length; @@ -96,7 +96,7 @@ public class BZip2CompressorInputStreamTest { @Test public void shouldThrowAnIOExceptionWhenAppliedToAZipFile() throws Exception { - try (InputStream in = Files.newInputStream(getFile("bla.zip").toPath())) { + try (InputStream in = newInputStream("bla.zip")) { assertThrows(IOException.class, () -> new BZip2CompressorInputStream(in)); } } diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStreamTest.java index ce401a09..a83595dc 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStreamTest.java @@ -48,8 +48,8 @@ public class BlockLZ4CompressorInputStreamTest extends AbstractTestCase { @Test public void readBlaLz4() throws IOException { - try (InputStream a = new BlockLZ4CompressorInputStream(Files.newInputStream(getFile("bla.tar.block_lz4").toPath())); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + try (InputStream a = new BlockLZ4CompressorInputStream(newInputStream("bla.tar.block_lz4")); + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java index 98501a5c..4cef1019 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java @@ -92,8 +92,8 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { @Test public void readBlaDumpLz4() throws IOException { - try (InputStream a = new FramedLZ4CompressorInputStream(Files.newInputStream(getFile("bla.dump.lz4").toPath())); - InputStream e = Files.newInputStream(getFile("bla.dump").toPath())) { + try (InputStream a = new FramedLZ4CompressorInputStream(newInputStream("bla.dump.lz4")); + InputStream e = newInputStream("bla.dump")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -102,8 +102,8 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { @Test public void readBlaLz4() throws IOException { - try (InputStream a = new FramedLZ4CompressorInputStream(Files.newInputStream(getFile("bla.tar.lz4").toPath())); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + try (InputStream a = new FramedLZ4CompressorInputStream(newInputStream("bla.tar.lz4")); + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -114,8 +114,8 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { public void readBlaLz4ViaFactory() throws Exception { try (InputStream a = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), - Files.newInputStream(getFile("bla.tar.lz4").toPath())); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + newInputStream("bla.tar.lz4")); + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -125,8 +125,8 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { @Test public void readBlaLz4ViaFactoryAutoDetection() throws Exception { try (InputStream a = new CompressorStreamFactory() - .createCompressorInputStream(new BufferedInputStream(Files.newInputStream(getFile("bla.tar.lz4").toPath()))); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + .createCompressorInputStream(new BufferedInputStream(newInputStream("bla.tar.lz4"))); + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -137,9 +137,9 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { public void readBlaLz4ViaFactoryWithDecompressConcatenated() throws Exception { try (InputStream a = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), - Files.newInputStream(getFile("bla.tar.lz4").toPath()), + newInputStream("bla.tar.lz4"), true); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -148,8 +148,8 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { @Test public void readBlaLz4WithDecompressConcatenated() throws IOException { - try (InputStream a = new FramedLZ4CompressorInputStream(Files.newInputStream(getFile("bla.tar.lz4").toPath()), true); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + try (InputStream a = new FramedLZ4CompressorInputStream(newInputStream("bla.tar.lz4"), true); + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -158,12 +158,12 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { private void readDoubledBlaLz4(final StreamWrapper wrapper, final boolean expectDuplicateOutput) throws Exception { byte[] singleInput; - try (InputStream i = Files.newInputStream(getFile("bla.tar.lz4").toPath())) { + try (InputStream i = newInputStream("bla.tar.lz4")) { singleInput = IOUtils.toByteArray(i); } final byte[] input = duplicate(singleInput); try (InputStream a = wrapper.wrap(new ByteArrayInputStream(input)); - InputStream e = Files.newInputStream(getFile("bla.tar").toPath())) { + InputStream e = newInputStream("bla.tar")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expectDuplicateOutput ? duplicate(expected) : expected, actual); @@ -340,7 +340,7 @@ public final class FramedLZ4CompressorInputStreamTest extends AbstractTestCase { @Test public void rejectsNonLZ4Stream() { - assertThrows(IOException.class, () -> new FramedLZ4CompressorInputStream(Files.newInputStream(getFile("bla.tar").toPath()))); + assertThrows(IOException.class, () -> new FramedLZ4CompressorInputStream(newInputStream("bla.tar"))); } @Test diff --git a/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java index d6acbe41..f8a6bcc6 100644 --- a/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java @@ -77,11 +77,11 @@ public final class FramedSnappyCompressorInputStreamTest @Test public void readIWAFileWithBiggerOffset() throws Exception { final File o = new File(dir, "COMPRESS-358.raw"); - try (InputStream is = Files.newInputStream(getFile("COMPRESS-358.iwa").toPath()); + try (InputStream is = newInputStream("COMPRESS-358.iwa"); FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(is, 1 << 16, FramedSnappyDialect.IWORK_ARCHIVE);) { Files.copy(in, o.toPath()); } - try (InputStream a = Files.newInputStream(o.toPath()); InputStream e = Files.newInputStream(getFile("COMPRESS-358.uncompressed").toPath())) { + try (InputStream a = Files.newInputStream(o.toPath()); InputStream e = newInputStream("COMPRESS-358.uncompressed")) { final byte[] expected = IOUtils.toByteArray(e); final byte[] actual = IOUtils.toByteArray(a); assertArrayEquals(expected, actual); @@ -103,7 +103,7 @@ public final class FramedSnappyCompressorInputStreamTest @Test public void testAvailable() throws Exception { - try (InputStream isSz = Files.newInputStream(getFile("mixed.txt.sz").toPath())) { + try (InputStream isSz = newInputStream("mixed.txt.sz")) { final FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(isSz); assertEquals(0, in.available()); // no chunk read so far assertEquals('1', in.read()); @@ -136,11 +136,11 @@ public final class FramedSnappyCompressorInputStreamTest public void testLoremIpsum() throws Exception { final File outputSz = new File(dir, "lorem-ipsum.1"); final File outputGz = new File(dir, "lorem-ipsum.2"); - try (InputStream isSz = Files.newInputStream(getFile("lorem-ipsum.txt.sz").toPath())) { + try (InputStream isSz = newInputStream("lorem-ipsum.txt.sz")) { try (InputStream in = new FramedSnappyCompressorInputStream(isSz)) { Files.copy(in, outputSz.toPath()); } - try (InputStream isGz = Files.newInputStream(getFile("lorem-ipsum.txt.gz").toPath()); InputStream in = new GzipCompressorInputStream(isGz)) { + try (InputStream isGz = newInputStream("lorem-ipsum.txt.gz"); InputStream in = new GzipCompressorInputStream(isGz)) { Files.copy(in, outputGz.toPath()); } } @@ -161,7 +161,7 @@ public final class FramedSnappyCompressorInputStreamTest @Test public void testRemainingChunkTypes() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); - try (InputStream isSz = Files.newInputStream(getFile("mixed.txt.sz").toPath())) { + try (InputStream isSz = newInputStream("mixed.txt.sz")) { final FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(isSz); IOUtils.copy(in, out); out.close();