Author: sebb Date: Tue Feb 17 17:40:54 2015 New Revision: 1660457 URL: http://svn.apache.org/r1660457 Log: COMPRESS-305 Convert all tests to JUnit4 style Convert the AbstractTestCase test cases
Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ChainingTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/BZip2TestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/DeflateTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/XZTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,7 @@ */ package org.apache.commons.compress; +import static org.junit.Assert.*; import java.io.BufferedInputStream; import java.io.Closeable; import java.io.File; @@ -34,15 +35,15 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; -import junit.framework.TestCase; - import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.utils.IOUtils; +import org.junit.After; +import org.junit.Before; -public abstract class AbstractTestCase extends TestCase { +public abstract class AbstractTestCase { protected File dir; protected File resultDir; @@ -52,15 +53,8 @@ public abstract class AbstractTestCase e protected ArchiveStreamFactory factory = new ArchiveStreamFactory(); - public AbstractTestCase() { - } - - public AbstractTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { dir = mkdir("dir"); resultDir = mkdir("dir-result"); archive = null; @@ -90,8 +84,8 @@ public abstract class AbstractTestCase e return new File(uri); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { rmdir(dir); rmdir(resultDir); dir = resultDir = null; Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTest.java Tue Feb 17 17:40:54 2015 @@ -18,17 +18,23 @@ package org.apache.commons.compress; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.io.IOException; +import java.io.FilenameFilter; import java.util.ArrayList; - -import junit.framework.Test; -import junit.framework.TestSuite; +import java.util.Collection; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveException; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; /** * Test that can read various archive file examples. @@ -37,55 +43,48 @@ import org.apache.commons.compress.archi * * Files must be in resources/archives, and there must be a file.txt containing * the list of files in the archives. - * - * The class uses nested suites in order to be able to name the test after the file name, - * as JUnit does not allow one to change the display name of a test. */ +@RunWith(Parameterized.class) public class ArchiveReadTest extends AbstractTestCase { - final static ClassLoader classLoader = ArchiveReadTest.class.getClassLoader(); + private static final ClassLoader CLASSLOADER = ArchiveReadTest.class.getClassLoader(); + private static final File ARCDIR = new File(CLASSLOADER.getResource("archives").getFile()); + private static final ArrayList<String> FILELIST = new ArrayList<String>(); private File file; - private static final ArrayList<String> fileList = new ArrayList<String>(); - public ArchiveReadTest(String name) { - super(name); - } - - private ArchiveReadTest(String name, File file){ - super(name); + public ArchiveReadTest(File file){ this.file = file; } - public static TestSuite suite() throws IOException{ - TestSuite suite = new TestSuite("ArchiveReadTests"); - // TODO move fileList setup to static block - File arcdir =new File(classLoader.getResource("archives").getFile()); - assertTrue(arcdir.exists()); - File listing= new File(arcdir,"files.txt"); + @BeforeClass + public static void setUpFileList() throws Exception { + assertTrue(ARCDIR.exists()); + File listing= new File(ARCDIR,"files.txt"); assertTrue("files.txt is readable",listing.canRead()); BufferedReader br = new BufferedReader(new FileReader(listing)); String line; - fileList.clear(); // Surefire calls the suite more than once while ((line=br.readLine())!=null){ - if (line.startsWith("#")){ - continue; + if (!line.startsWith("#")){ + FILELIST.add(line); } - fileList.add(line); } br.close(); - File[]files=arcdir.listFiles(); - for (final File file : files) { - if (file.getName().endsWith(".txt")){ - continue; + } + + @Parameters + public static Collection<Object[]> data() { + assertTrue(ARCDIR.exists()); + Collection<Object[]> params = new ArrayList<Object[]>(); + for (File f : ARCDIR.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return !name.endsWith(".txt"); } - // Appears to be the only way to give the test a variable name - TestSuite namedSuite = new TestSuite(file.getName()); - Test test = new ArchiveReadTest("testArchive", file); - namedSuite.addTest(test); - suite.addTest(namedSuite); + })) + { + params.add(new Object[] { f }); } - return suite; + return params; } // files.txt contains size and filename @@ -94,14 +93,15 @@ public class ArchiveReadTest extends Abs return entry.getSize() + " " + entry.getName(); } + @Test public void testArchive() throws Exception{ @SuppressWarnings("unchecked") // fileList is correct type already - ArrayList<String> expected= (ArrayList<String>) fileList.clone(); + ArrayList<String> expected= (ArrayList<String>) FILELIST.clone(); try { checkArchiveContent(file, expected); } catch (ArchiveException e) { fail("Problem checking "+file); - } catch (junit.framework.AssertionFailedError e) { // show error in context + } catch (AssertionError e) { // show error in context fail("Problem checking " + file + " " +e); } } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java Tue Feb 17 17:40:54 2015 @@ -18,7 +18,10 @@ package org.apache.commons.compress; +import static org.junit.Assert.*; + import org.apache.commons.compress.utils.ArchiveUtils; +import org.junit.Test; public class ArchiveUtilsTest extends AbstractTestCase { @@ -31,6 +34,8 @@ public class ArchiveUtilsTest extends Ab i += 2; } } + + @Test public void testCompareBA(){ byte[] buffer1 = {1,2,3}; byte[] buffer2 = {1,2,3,0}; @@ -45,6 +50,7 @@ public class ArchiveUtilsTest extends Ab assertTrue(ArchiveUtils.isEqual(buffer3, buffer1)); } + @Test public void testCompareAscii(){ byte[] buffer1 = {'a','b','c'}; byte[] buffer2 = {'d','e','f',0}; @@ -54,6 +60,7 @@ public class ArchiveUtilsTest extends Ab assertFalse(ArchiveUtils.matchAsciiBuffer("def", buffer2)); } + @Test public void testAsciiConversions() { asciiToByteAndBackOK(""); asciiToByteAndBackOK("abcd"); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ChainingTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ChainingTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ChainingTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ChainingTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ package org.apache.commons.compress; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; @@ -25,10 +27,12 @@ import org.apache.commons.compress.archi 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.Test; public class ChainingTestCase extends AbstractTestCase { + @Test public void testTarGzip() throws Exception { File file = getFile("bla.tgz"); final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file))); @@ -38,6 +42,7 @@ public class ChainingTestCase extends Ab is.close(); } + @Test public void testTarBzip2() throws Exception { File file = getFile("bla.tar.bz2"); final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file))); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress; +import static org.junit.Assert.*; + import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -30,14 +32,13 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +import org.junit.Test; public final class DetectArchiverTestCase extends AbstractTestCase { - public DetectArchiverTestCase(String name) { - super(name); - } final ClassLoader classLoader = getClass().getClassLoader(); + @Test public void testDetectionNotArchive() throws IOException { try { getStreamFor("test.txt"); @@ -47,12 +48,14 @@ public final class DetectArchiverTestCas } } + @Test public void testCOMPRESS117() throws Exception { final ArchiveInputStream tar = getStreamFor("COMPRESS-117.tar"); assertNotNull(tar); assertTrue(tar instanceof TarArchiveInputStream); } + @Test public void testDetection() throws Exception { final ArchiveInputStream ar = getStreamFor("bla.ar"); @@ -100,10 +103,12 @@ public final class DetectArchiverTestCas // emptyArchive("ar"); // } + @Test public void testEmptyCpioArchive() throws Exception { checkEmptyArchive("cpio"); } + @Test public void testEmptyJarArchive() throws Exception { checkEmptyArchive("jar"); } @@ -112,6 +117,7 @@ public final class DetectArchiverTestCas // public void testEmptyTarArchive() throws Exception { // checkEmptyArchive("tar"); // } + @Test public void testEmptyZipArchive() throws Exception { checkEmptyArchive("zip"); } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ package org.apache.commons.compress; +import static org.junit.Assert.*; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -32,6 +34,7 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.jar.JarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.junit.Test; /** * Check that the different write methods create the same output. @@ -49,44 +52,58 @@ public class IOMethodsTest extends Abstr } } + @Test public void testWriteAr() throws Exception { ArchiveEntry entry = new ArArchiveEntry("dummy", bytesToTest); compareWrites("ar", entry); } + + @Test public void testWriteCpio() throws Exception { ArchiveEntry entry = new CpioArchiveEntry("dummy", bytesToTest); compareWrites("cpio", entry); } + + @Test public void testWriteJar() throws Exception { ArchiveEntry entry = new JarArchiveEntry("dummy"); compareWrites("jar", entry); } + + @Test public void testWriteTar() throws Exception { TarArchiveEntry entry = new TarArchiveEntry("dummy"); entry.setSize(bytesToTest); compareWrites("tar", entry); } + + @Test public void testWriteZip() throws Exception { ArchiveEntry entry = new ZipArchiveEntry("dummy"); compareWrites("zip", entry); } + @Test public void testReadAr() throws Exception { compareReads("ar"); } + @Test public void testReadCpio() throws Exception { compareReads("cpio"); } + @Test public void testReadJar() throws Exception { compareReads("jar"); } + @Test public void testReadTar() throws Exception { compareReads("tar"); } + @Test public void testReadZip() throws Exception { compareReads("zip"); } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -31,9 +33,12 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.ar.ArArchiveInputStream; import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Ignore; +import org.junit.Test; public final class ArTestCase extends AbstractTestCase { + @Test public void testArArchiveCreation() throws Exception { final File output = new File(dir, "bla.ar"); @@ -53,6 +58,7 @@ public final class ArTestCase extends Ab os.close(); } + @Test public void testArUnarchive() throws Exception { final File output = new File(dir, "bla.ar"); { @@ -88,6 +94,7 @@ public final class ArTestCase extends Ab is.close(); } + @Test public void testArDelete() throws Exception { final File output = new File(dir, "bla.ar"); @@ -182,6 +189,8 @@ public final class ArTestCase extends Ab } // TODO: revisit - does AR not support storing directories? + @Ignore + @Test public void XtestDirectoryEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -222,6 +231,8 @@ public final class ArTestCase extends Ab } // TODO: revisit - does AR not support storing directories? + @Ignore + @Test public void XtestExplicitDirectoryEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -261,6 +272,7 @@ public final class ArTestCase extends Ab } } + @Test public void testFileEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -310,6 +322,7 @@ public final class ArTestCase extends Ab } } + @Test public void testExplicitFileEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -32,19 +34,11 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Test; public class ArchiveOutputStreamTest extends AbstractTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testFinish() throws Exception { OutputStream out1 = new ByteArrayOutputStream(); @@ -94,6 +88,7 @@ public class ArchiveOutputStreamTest ext } } + @Test public void testOptionalFinish() throws Exception { OutputStream out1 = new ByteArrayOutputStream(); @@ -114,22 +109,27 @@ public class ArchiveOutputStreamTest ext } } + @Test public void testCallSequenceAr() throws Exception{ doCallSequence("Ar"); } + @Test public void testCallSequenceCpio() throws Exception{ doCallSequence("Cpio"); } + @Test public void testCallSequenceJar() throws Exception{ doCallSequence("Jar"); } + @Test public void testCallSequenceTar() throws Exception{ doCallSequence("Tar"); } + @Test public void testCallSequenceZip() throws Exception{ doCallSequence("Zip"); } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -32,9 +34,11 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream; import org.apache.commons.compress.archivers.cpio.CpioConstants; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Test; public final class CpioTestCase extends AbstractTestCase { + @Test public void testCpioArchiveCreation() throws Exception { final File output = new File(dir, "bla.cpio"); @@ -55,6 +59,7 @@ public final class CpioTestCase extends out.close(); } + @Test public void testCpioUnarchive() throws Exception { final File output = new File(dir, "bla.cpio"); final File file1 = getFile("test1.xml"); @@ -108,6 +113,7 @@ public final class CpioTestCase extends assertEquals("length of " + t.getAbsolutePath(), file2Length, t.length()); } + @Test public void testDirectoryEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -147,6 +153,7 @@ public final class CpioTestCase extends } } + @Test public void testExplicitDirectoryEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -187,6 +194,7 @@ public final class CpioTestCase extends } } + @Test public void testFileEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -235,6 +243,7 @@ public final class CpioTestCase extends } } + @Test public void testExplicitFileEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -29,13 +31,16 @@ import java.util.ArrayList; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.dump.DumpArchiveInputStream; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Test; public final class DumpTestCase extends AbstractTestCase { + @Test public void testDumpUnarchiveAll() throws Exception { unarchiveAll(getFile("bla.dump")); } + @Test public void testCompressedDumpUnarchiveAll() throws Exception { unarchiveAll(getFile("bla.z.dump")); } @@ -74,10 +79,12 @@ public final class DumpTestCase extends } } + @Test public void testArchiveDetection() throws Exception { archiveDetection(getFile("bla.dump")); } + @Test public void testCompressedArchiveDetection() throws Exception { archiveDetection(getFile("bla.z.dump")); } @@ -94,10 +101,12 @@ public final class DumpTestCase extends } } + @Test public void testCheckArchive() throws Exception { checkDumpArchive(getFile("bla.dump")); } + @Test public void testCheckCompressedArchive() throws Exception { checkDumpArchive(getFile("bla.z.dump")); } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java Tue Feb 17 17:40:54 2015 @@ -27,8 +27,11 @@ import java.io.OutputStream; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Test; public final class JarTestCase extends AbstractTestCase { + + @Test public void testJarArchiveCreation() throws Exception { final File output = new File(dir, "bla.jar"); @@ -51,6 +54,7 @@ public final class JarTestCase extends A } + @Test public void testJarUnarchive() throws Exception { final File input = getFile("bla.jar"); final InputStream is = new FileInputStream(input); @@ -81,6 +85,7 @@ public final class JarTestCase extends A is.close(); } + @Test public void testJarUnarchiveAll() throws Exception { final File input = getFile("bla.jar"); final InputStream is = new FileInputStream(input); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java Tue Feb 17 17:40:54 2015 @@ -18,87 +18,79 @@ package org.apache.commons.compress.archivers; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; -import java.io.IOException; +import java.io.FilenameFilter; import java.util.ArrayList; -import java.util.Map; -import java.util.HashMap; +import java.util.Collection; import junit.framework.AssertionFailedError; -import junit.framework.Test; -import junit.framework.TestSuite; import org.apache.commons.compress.AbstractTestCase; +import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ar.ArArchiveInputStream; import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; /** * Test that can read various tar file examples. * - * The class uses nested suites in order to be able to name the test after the file name, - * as JUnit does not allow one to change the display name of a test. - */ + * Files must be in resources/longpath, and there must be a file.txt containing + * the list of files in the archives. +*/ +@RunWith(Parameterized.class) public class LongPathTest extends AbstractTestCase { - private String name; - private File file; - - private static final Map<String, ArrayList<String>> fileLists = new HashMap<String, ArrayList<String>>(); + private static final ClassLoader CLASSLOADER = LongPathTest.class.getClassLoader(); + private static final File ARCDIR = new File(CLASSLOADER.getResource("longpath").getFile()); + private static final ArrayList<String> FILELIST = new ArrayList<String>(); - public LongPathTest(String name) { - super(name); - } + private File file; - private LongPathTest(String name, String function, File file) { - super(function); - this.name = name; + public LongPathTest(File file){ this.file = file; } - public static TestSuite suite() throws IOException{ - TestSuite suite = new TestSuite("LongPathTests"); - suite.addTest(createSuite("LongPathTest", "longpath")); - suite.addTest(createSuite("LongSymlinkTest", "longsymlink")); - return suite; - } - - public static TestSuite createSuite(String name, String dirname) throws IOException { - TestSuite suite = new TestSuite(name); - File arcdir = getFile(dirname); - assertTrue(arcdir.exists()); - File listing= new File(arcdir,"files.txt"); - assertTrue("File listing is readable",listing.canRead()); + @BeforeClass + public static void setUpFileList() throws Exception { + assertTrue(ARCDIR.exists()); + File listing= new File(ARCDIR,"files.txt"); + assertTrue("files.txt is readable",listing.canRead()); BufferedReader br = new BufferedReader(new FileReader(listing)); - - ArrayList<String> fileList = new ArrayList<String>(); String line; while ((line=br.readLine())!=null){ - if (line.startsWith("#")){ - continue; + if (!line.startsWith("#")){ + FILELIST.add(line); } - fileList.add(line); } - fileLists.put(name, fileList); br.close(); - File[]files=arcdir.listFiles(); - for (final File file : files) { - if (file.getName().endsWith(".txt")){ - continue; + } + + @Parameters + public static Collection<Object[]> data() { + Collection<Object[]> params = new ArrayList<Object[]>(); + for (File f : ARCDIR.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return !name.endsWith(".txt"); } - // Appears to be the only way to give the test a variable name - TestSuite namedSuite = new TestSuite(file.getName()); - Test test = new LongPathTest(name, "testArchive", file); - namedSuite.addTest(test); - suite.addTest(namedSuite); + })) + { + params.add(new Object[] { f }); } - return suite; + return params; } @Override @@ -112,10 +104,10 @@ public class LongPathTest extends Abstra return entry.getName(); } + @Test public void testArchive() throws Exception { - ArrayList<String> fileList = fileLists.get(name); @SuppressWarnings("unchecked") // fileList is of correct type - ArrayList<String> expected = (ArrayList<String>) fileList.clone(); + ArrayList<String> expected = (ArrayList<String>) FILELIST.clone(); String name = file.getName(); if ("minotaur.jar".equals(name) || "minotaur-0.jar".equals(name)){ expected.add("META-INF/"); @@ -140,7 +132,7 @@ public class LongPathTest extends Abstra assertTrue(ais instanceof ArArchiveInputStream); // CPIO does not store directories or directory names expected.clear(); - for (String ent : fileList) { + for (String ent : FILELIST) { if (!ent.endsWith("/")) {// not a directory final int lastSlash = ent.lastIndexOf('/'); if (lastSlash >= 0) { // extract path name Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java?rev=1660457&view=auto ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java (added) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java Tue Feb 17 17:40:54 2015 @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.commons.compress.archivers; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.Collection; + +import junit.framework.AssertionFailedError; + +import org.apache.commons.compress.AbstractTestCase; +import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ar.ArArchiveInputStream; +import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test that can read various tar file examples. + * + * Files must be in resources/longsymlink, and there must be a file.txt containing + * the list of files in the archives. +*/ +@RunWith(Parameterized.class) +public class LongSymLinkTest extends AbstractTestCase { + + private static final ClassLoader CLASSLOADER = LongSymLinkTest.class.getClassLoader(); + private static final File ARCDIR = new File(CLASSLOADER.getResource("longsymlink").getFile()); + private static final ArrayList<String> FILELIST = new ArrayList<String>(); + + private File file; + + public LongSymLinkTest(File file){ + this.file = file; + } + + @BeforeClass + public static void setUpFileList() throws Exception { + assertTrue(ARCDIR.exists()); + File listing= new File(ARCDIR,"files.txt"); + assertTrue("files.txt is readable",listing.canRead()); + BufferedReader br = new BufferedReader(new FileReader(listing)); + String line; + while ((line=br.readLine())!=null){ + if (!line.startsWith("#")){ + FILELIST.add(line); + } + } + br.close(); + } + + @Parameters + public static Collection<Object[]> data() { + Collection<Object[]> params = new ArrayList<Object[]>(); + for (File f : ARCDIR.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return !name.endsWith(".txt"); + } + })) + { + params.add(new Object[] { f }); + } + return params; + } + + + @Override + protected String getExpectedString(ArchiveEntry entry) { + if (entry instanceof TarArchiveEntry) { + TarArchiveEntry tarEntry = (TarArchiveEntry) entry; + if (tarEntry.isSymbolicLink()) { + return tarEntry.getName() + " -> " + tarEntry.getLinkName(); + } + } + return entry.getName(); + } + + @Test + public void testArchive() throws Exception { + @SuppressWarnings("unchecked") // fileList is of correct type + ArrayList<String> expected = (ArrayList<String>) FILELIST.clone(); + String name = file.getName(); + if ("minotaur.jar".equals(name) || "minotaur-0.jar".equals(name)){ + expected.add("META-INF/"); + expected.add("META-INF/MANIFEST.MF"); + } + ArchiveInputStream ais = factory.createArchiveInputStream(new BufferedInputStream(new FileInputStream(file))); + // check if expected type recognised + if (name.endsWith(".tar")){ + assertTrue(ais instanceof TarArchiveInputStream); + } else if (name.endsWith(".jar") || name.endsWith(".zip")){ + assertTrue(ais instanceof ZipArchiveInputStream); + } else if (name.endsWith(".cpio")){ + assertTrue(ais instanceof CpioArchiveInputStream); + // Hack: cpio does not add trailing "/" to directory names + for(int i=0; i < expected.size(); i++){ + String ent = expected.get(i); + if (ent.endsWith("/")){ + expected.set(i, ent.substring(0, ent.length()-1)); + } + } + } else if (name.endsWith(".ar")){ + assertTrue(ais instanceof ArArchiveInputStream); + // CPIO does not store directories or directory names + expected.clear(); + for (String ent : FILELIST) { + if (!ent.endsWith("/")) {// not a directory + final int lastSlash = ent.lastIndexOf('/'); + if (lastSlash >= 0) { // extract path name + expected.add(ent.substring(lastSlash + 1, ent.length())); + } else { + expected.add(ent); + } + } + } + } else { + fail("Unexpected file type: "+name); + } + try { + checkArchiveContent(ais, expected); + } catch (AssertionFailedError e) { + fail("Error processing "+file.getName()+" "+e); + } finally { + ais.close(); + } + } +} Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java Tue Feb 17 17:40:54 2015 @@ -17,6 +17,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -26,21 +28,26 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.sevenz.SevenZFile; import org.apache.commons.compress.archivers.sevenz.SevenZMethod; import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; +import org.junit.Test; public class SevenZTestCase extends AbstractTestCase { + @Test public void testSevenZArchiveCreationUsingCopy() throws Exception { testSevenZArchiveCreation(SevenZMethod.COPY); } + @Test public void testSevenZArchiveCreationUsingLZMA2() throws Exception { testSevenZArchiveCreation(SevenZMethod.LZMA2); } + @Test public void testSevenZArchiveCreationUsingBZIP2() throws Exception { testSevenZArchiveCreation(SevenZMethod.BZIP2); } + @Test public void testSevenZArchiveCreationUsingDeflate() throws Exception { testSevenZArchiveCreation(SevenZMethod.DEFLATE); } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -31,8 +33,11 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Test; public final class TarTestCase extends AbstractTestCase { + + @Test public void testTarArchiveCreation() throws Exception { final File output = new File(dir, "bla.tar"); final File file1 = getFile("test1.xml"); @@ -52,6 +57,7 @@ public final class TarTestCase extends A os.close(); } + @Test public void testTarArchiveLongNameCreation() throws Exception { String name = "testdata/12345678901234567890123456789012345678901234567890123456789012345678901234567890123456.xml"; byte[] bytes = name.getBytes(CharsetNames.UTF_8); @@ -104,6 +110,7 @@ public final class TarTestCase extends A } } + @Test public void testTarUnarchive() throws Exception { final File input = getFile("bla.tar"); final InputStream is = new FileInputStream(input); @@ -115,6 +122,7 @@ public final class TarTestCase extends A out.close(); } + @Test public void testCOMPRESS114() throws Exception { final File input = getFile("COMPRESS-114.tar"); final InputStream is = new FileInputStream(input); @@ -127,6 +135,7 @@ public final class TarTestCase extends A in.close(); } + @Test public void testDirectoryEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -166,6 +175,7 @@ public final class TarTestCase extends A } } + @Test public void testExplicitDirectoryEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -205,6 +215,7 @@ public final class TarTestCase extends A } } + @Test public void testFileEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -253,6 +264,7 @@ public final class TarTestCase extends A } } + @Test public void testExplicitFileEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -303,6 +315,7 @@ public final class TarTestCase extends A } } + @Test public void testCOMPRESS178() throws Exception { final File input = getFile("COMPRESS-178.tar"); final InputStream is = new FileInputStream(input); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers; +import static org.junit.Assert.*; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -40,6 +42,7 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.zip.ZipMethod; import org.apache.commons.compress.utils.IOUtils; import org.junit.Assert; +import org.junit.Test; public final class ZipTestCase extends AbstractTestCase { /** @@ -47,6 +50,7 @@ public final class ZipTestCase extends A * and source is the same, it looks like the operations have worked * @throws Exception */ + @Test public void testZipArchiveCreation() throws Exception { // Archive final File output = new File(dir, "bla.zip"); @@ -111,6 +115,7 @@ public final class ZipTestCase extends A * Simple unarchive test. Asserts nothing. * @throws Exception */ + @Test public void testZipUnarchive() throws Exception { final File input = getFile("bla.zip"); final InputStream is = new FileInputStream(input); @@ -127,6 +132,7 @@ public final class ZipTestCase extends A * <a href="https://issues.apache.org/jira/browse/COMPRESS-208" * >COMPRESS-208</a>. */ + @Test public void testSkipsPK00Prefix() throws Exception { final File input = getFile("COMPRESS-208.zip"); InputStream is = new FileInputStream(input); @@ -145,6 +151,7 @@ public final class ZipTestCase extends A * <a href="https://issues.apache.org/jira/browse/COMPRESS-93" * >COMPRESS-93</a>. */ + @Test public void testSupportedCompressionMethod() throws IOException { /* ZipFile bla = new ZipFile(getFile("bla.zip")); @@ -167,6 +174,7 @@ public final class ZipTestCase extends A * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-93" * >COMPRESS-93</a> */ + @Test public void testSkipEntryWithUnsupportedCompressionMethod() throws IOException { ZipArchiveInputStream zip = @@ -196,6 +204,7 @@ public final class ZipTestCase extends A * * @throws Exception */ + @Test public void testListAllFilesWithNestedArchive() throws Exception { final File input = getFile("OSX_ArchiveWithNestedArchive.zip"); @@ -230,6 +239,7 @@ public final class ZipTestCase extends A results.contains("test3.xml"); } + @Test public void testDirectoryEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -265,6 +275,7 @@ public final class ZipTestCase extends A } } + @Test public void testExplicitDirectoryEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -307,6 +318,7 @@ public final class ZipTestCase extends A } }; + @Test public void testCopyRawEntriesFromFile() throws IOException { @@ -338,6 +350,7 @@ public final class ZipTestCase extends A zf2.close(); } + @Test public void testCopyRawZip64EntryFromFile() throws IOException { @@ -362,6 +375,8 @@ public final class ZipTestCase extends A assertSameFileContents(reference, fileResult); zf1.close(); } + + @Test public void testUnixModeInAddRaw() throws IOException { File[] tmp = createTempDirAndFile(); @@ -449,6 +464,7 @@ public final class ZipTestCase extends A zos.closeArchiveEntry(); } + @Test public void testFileEntryFromFile() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; @@ -493,6 +509,7 @@ public final class ZipTestCase extends A } } + @Test public void testExplicitFileEntry() throws Exception { File[] tmp = createTempDirAndFile(); File archive = null; Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,19 +18,24 @@ package org.apache.commons.compress.archivers.ar; +import static org.junit.Assert.*; + import java.io.BufferedInputStream; import java.io.FileInputStream; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.utils.ArchiveUtils; +import org.junit.Test; public class ArArchiveInputStreamTest extends AbstractTestCase { + @Test public void testReadLongNamesGNU() throws Exception { checkLongNameEntry("longfile_gnu.ar"); } + @Test public void testReadLongNamesBSD() throws Exception { checkLongNameEntry("longfile_bsd.ar"); } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ package org.apache.commons.compress.archivers.ar; +import static org.junit.Assert.*; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -26,9 +28,11 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.compress.AbstractTestCase; +import org.junit.Test; public class ArArchiveOutputStreamTest extends AbstractTestCase { + @Test public void testLongFileNamesCauseExceptionByDefault() { ArArchiveOutputStream os = null; try { @@ -44,6 +48,7 @@ public class ArArchiveOutputStreamTest e } } + @Test public void testLongFileNamesWorkUsingBSDDialect() throws Exception { FileOutputStream fos = null; ArArchiveOutputStream os = null; Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -19,14 +19,18 @@ package org.apache.commons.compress.archivers.arj; +import static org.junit.Assert.*; + import java.io.FileInputStream; import java.util.Calendar; import java.util.TimeZone; import org.apache.commons.compress.AbstractTestCase; +import org.junit.Test; public class ArjArchiveInputStreamTest extends AbstractTestCase { + @Test public void testArjUnarchive() throws Exception { StringBuilder expected = new StringBuilder(); expected.append("test1.xml<?xml version=\"1.0\"?>\n"); @@ -50,6 +54,7 @@ public class ArjArchiveInputStreamTest e assertEquals(result.toString(), expected.toString()); } + @Test public void testReadingOfAttributesDosVersion() throws Exception { ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.arj"))); ArjArchiveEntry entry = in.getNextEntry(); @@ -63,6 +68,7 @@ public class ArjArchiveInputStreamTest e in.close(); } + @Test public void testReadingOfAttributesUnixVersion() throws Exception { ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.unix.arj"))); ArjArchiveEntry entry = in.getNextEntry(); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,12 +18,16 @@ */ package org.apache.commons.compress.archivers.cpio; +import static org.junit.Assert.*; + import java.io.FileInputStream; import org.apache.commons.compress.AbstractTestCase; +import org.junit.Test; public class CpioArchiveInputStreamTest extends AbstractTestCase { + @Test public void testCpioUnarchive() throws Exception { StringBuilder expected = new StringBuilder(); expected.append("./test1.xml<?xml version=\"1.0\"?>\n"); @@ -46,6 +50,7 @@ public class CpioArchiveInputStreamTest assertEquals(result.toString(), expected.toString()); } + @Test public void testCpioUnarchiveCreatedByRedlineRpm() throws Exception { CpioArchiveInputStream in = new CpioArchiveInputStream(new FileInputStream(getFile("redline.cpio"))); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ */ package org.apache.commons.compress.archivers.cpio; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -25,9 +27,11 @@ import java.io.InputStream; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.utils.IOUtils; +import org.junit.Test; public class CpioArchiveOutputStreamTest extends AbstractTestCase { + @Test public void testWriteOldBinary() throws Exception { final File f = getFile("test1.xml"); final File output = new File(dir, "test.cpio"); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,16 +18,18 @@ */ package org.apache.commons.compress.archivers.dump; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.*; import java.io.FileInputStream; import java.io.InputStream; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveException; +import org.junit.Test; public class DumpArchiveInputStreamTest extends AbstractTestCase { + @Test public void testNotADumpArchive() throws Exception { FileInputStream is = new FileInputStream(getFile("bla.zip")); try { @@ -41,6 +43,7 @@ public class DumpArchiveInputStreamTest } } + @Test public void testNotADumpArchiveButBigEnough() throws Exception { FileInputStream is = new FileInputStream(getFile("zip64support.tar.bz2")); try { @@ -54,6 +57,7 @@ public class DumpArchiveInputStreamTest } } + @Test public void testConsumesArchiveCompletely() throws Exception { InputStream is = DumpArchiveInputStreamTest.class .getResourceAsStream("/archive_with_trailer.dump"); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java Tue Feb 17 17:40:54 2015 @@ -17,17 +17,21 @@ */ package org.apache.commons.compress.archivers.sevenz; +import static org.junit.Assert.*; + import java.io.File; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import javax.crypto.Cipher; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.PasswordRequiredException; +import org.junit.Test; public class SevenZFileTest extends AbstractTestCase { private static final String TEST2_CONTENT = "<?xml version = '1.0'?>\r\n<!DOCTYPE" + " connections>\r\n<meinxml>\r\n\t<leer />\r\n</meinxml>\n"; + @Test public void testAllEmptyFilesArchive() throws Exception { SevenZFile archive = new SevenZFile(getFile("7z-empty-mhc-off.7z")); try { @@ -37,22 +41,27 @@ public class SevenZFileTest extends Abst } } + @Test public void testHelloWorldHeaderCompressionOffCopy() throws Exception { checkHelloWorld("7z-hello-mhc-off-copy.7z"); } + @Test public void testHelloWorldHeaderCompressionOffLZMA2() throws Exception { checkHelloWorld("7z-hello-mhc-off-lzma2.7z"); } + @Test public void test7zUnarchive() throws Exception { test7zUnarchive(getFile("bla.7z"), SevenZMethod.LZMA); } + @Test public void test7zDeflateUnarchive() throws Exception { test7zUnarchive(getFile("bla.deflate.7z"), SevenZMethod.DEFLATE); } + @Test public void test7zDecryptUnarchive() throws Exception { if (isStrongCryptoAvailable()) { test7zUnarchive(getFile("bla.encrypted.7z"), SevenZMethod.LZMA, // stack LZMA + AES @@ -64,6 +73,7 @@ public class SevenZFileTest extends Abst test7zUnarchive(f, m, null); } + @Test public void testEncryptedArchiveRequiresPassword() throws Exception { try { new SevenZFile(getFile("bla.encrypted.7z")); @@ -82,6 +92,7 @@ public class SevenZFileTest extends Abst /** * @see "https://issues.apache.org/jira/browse/COMPRESS-256" */ + @Test public void testCompressedHeaderWithNonDefaultDictionarySize() throws Exception { SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-256.7z")); try { @@ -95,6 +106,7 @@ public class SevenZFileTest extends Abst } } + @Test public void testSignatureCheck() { assertTrue(SevenZFile.matches(SevenZFile.sevenZSignature, SevenZFile.sevenZSignature.length)); @@ -109,6 +121,7 @@ public class SevenZFileTest extends Abst (byte) 0xAF, 0x27, 0x1D}, 6)); } + @Test public void testReadingBackLZMA2DictSize() throws Exception { File output = new File(dir, "lzma2-dictsize.7z"); SevenZOutputFile outArchive = new SevenZOutputFile(output); @@ -134,6 +147,7 @@ public class SevenZFileTest extends Abst } } + @Test public void testReadingBackDeltaDistance() throws Exception { File output = new File(dir, "delta-distance.7z"); SevenZOutputFile outArchive = new SevenZOutputFile(output); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java Tue Feb 17 17:40:54 2015 @@ -17,6 +17,9 @@ */ package org.apache.commons.compress.archivers.sevenz; +import static org.junit.Assert.*; +import org.junit.Test; + import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -49,6 +52,7 @@ public class SevenZOutputFileTest extend super.tearDown(); } + @Test public void testDirectoriesAndEmptyFiles() throws Exception { output = new File(dir, "empties.7z"); @@ -145,6 +149,7 @@ public class SevenZOutputFileTest extend } + @Test public void testDirectoriesOnly() throws Exception { output = new File(dir, "dirs.7z"); SevenZOutputFile outArchive = new SevenZOutputFile(output); @@ -173,6 +178,7 @@ public class SevenZOutputFileTest extend } + @Test public void testCantFinishTwice() throws Exception { output = new File(dir, "finish.7z"); SevenZOutputFile outArchive = new SevenZOutputFile(output); @@ -187,96 +193,118 @@ public class SevenZOutputFileTest extend } } + @Test public void testSixEmptyFiles() throws Exception { testCompress252(6, 0); } + @Test public void testSixFilesSomeNotEmpty() throws Exception { testCompress252(6, 2); } + @Test public void testSevenEmptyFiles() throws Exception { testCompress252(7, 0); } + @Test public void testSevenFilesSomeNotEmpty() throws Exception { testCompress252(7, 2); } + @Test public void testEightEmptyFiles() throws Exception { testCompress252(8, 0); } + @Test public void testEightFilesSomeNotEmpty() throws Exception { testCompress252(8, 2); } + @Test public void testNineEmptyFiles() throws Exception { testCompress252(9, 0); } + @Test public void testNineFilesSomeNotEmpty() throws Exception { testCompress252(9, 2); } + @Test public void testTwentyNineEmptyFiles() throws Exception { testCompress252(29, 0); } + @Test public void testTwentyNineFilesSomeNotEmpty() throws Exception { testCompress252(29, 7); } + @Test public void testCopyRoundtrip() throws Exception { testRoundTrip(SevenZMethod.COPY); } + @Test public void testBzip2Roundtrip() throws Exception { testRoundTrip(SevenZMethod.BZIP2); } + @Test public void testLzma2Roundtrip() throws Exception { testRoundTrip(SevenZMethod.LZMA2); } + @Test public void testDeflateRoundtrip() throws Exception { testRoundTrip(SevenZMethod.DEFLATE); } + @Test public void testBCJX86Roundtrip() throws Exception { if (XZ_BCJ_IS_BUGGY) { return; } testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.BCJ_X86_FILTER)); } + @Test public void testBCJARMRoundtrip() throws Exception { if (XZ_BCJ_IS_BUGGY) { return; } testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.BCJ_ARM_FILTER)); } + @Test public void testBCJARMThumbRoundtrip() throws Exception { if (XZ_BCJ_IS_BUGGY) { return; } testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.BCJ_ARM_THUMB_FILTER)); } + @Test public void testBCJIA64Roundtrip() throws Exception { if (XZ_BCJ_IS_BUGGY) { return; } testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.BCJ_IA64_FILTER)); } + @Test public void testBCJPPCRoundtrip() throws Exception { if (XZ_BCJ_IS_BUGGY) { return; } testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.BCJ_PPC_FILTER)); } + @Test public void testBCJSparcRoundtrip() throws Exception { if (XZ_BCJ_IS_BUGGY) { return; } testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.BCJ_SPARC_FILTER)); } + @Test public void testDeltaRoundtrip() throws Exception { testFilterRoundTrip(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER)); } + @Test public void testStackOfContentCompressions() throws Exception { output = new File(dir, "multiple-methods.7z"); ArrayList<SevenZMethodConfiguration> methods = new ArrayList<SevenZMethodConfiguration>(); @@ -287,6 +315,7 @@ public class SevenZOutputFileTest extend createAndReadBack(output, methods); } + @Test public void testDeflateWithConfiguration() throws Exception { output = new File(dir, "deflate-options.7z"); // Deflater.BEST_SPEED @@ -294,6 +323,7 @@ public class SevenZOutputFileTest extend .singletonList(new SevenZMethodConfiguration(SevenZMethod.DEFLATE, 1))); } + @Test public void testBzip2WithConfiguration() throws Exception { output = new File(dir, "bzip2-options.7z"); // 400k block size @@ -301,6 +331,7 @@ public class SevenZOutputFileTest extend .singletonList(new SevenZMethodConfiguration(SevenZMethod.BZIP2, 4))); } + @Test public void testLzma2WithIntConfiguration() throws Exception { output = new File(dir, "lzma2-options.7z"); // 1 MB dictionary @@ -308,6 +339,7 @@ public class SevenZOutputFileTest extend .singletonList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1 << 20))); } + @Test public void testLzma2WithOptionsConfiguration() throws Exception { output = new File(dir, "lzma2-options2.7z"); LZMA2Options opts = new LZMA2Options(1); @@ -315,6 +347,7 @@ public class SevenZOutputFileTest extend .singletonList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, opts))); } + @Test public void testArchiveWithMixedMethods() throws Exception { output = new File(dir, "mixed-methods.7z"); SevenZOutputFile outArchive = new SevenZOutputFile(output); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ package org.apache.commons.compress.archivers.tar; +import static org.junit.Assert.*; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -37,11 +39,12 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.IOUtils; - import org.junit.Assert; +import org.junit.Test; public class TarArchiveOutputStreamTest extends AbstractTestCase { + @Test public void testCount() throws Exception { File f = File.createTempFile("commons-compress-tarcount", ".tar"); f.deleteOnExit(); @@ -69,6 +72,7 @@ public class TarArchiveOutputStreamTest assertEquals(f.length(), tarOut.getBytesWritten()); } + @Test public void testMaxFileSizeError() throws Exception { TarArchiveEntry t = new TarArchiveEntry("foo"); t.setSize(077777777777L); @@ -84,6 +88,7 @@ public class TarArchiveOutputStreamTest } } + @Test public void testBigNumberStarMode() throws Exception { TarArchiveEntry t = new TarArchiveEntry("foo"); t.setSize(0100000000000L); @@ -109,6 +114,7 @@ public class TarArchiveOutputStreamTest closeQuietly(tos); } + @Test public void testBigNumberPosixMode() throws Exception { TarArchiveEntry t = new TarArchiveEntry("foo"); t.setSize(0100000000000L); @@ -136,6 +142,7 @@ public class TarArchiveOutputStreamTest closeQuietly(tos); } + @Test public void testWriteSimplePaxHeaders() throws Exception { Map<String, String> m = new HashMap<String, String>(); m.put("a", "b"); @@ -149,6 +156,7 @@ public class TarArchiveOutputStreamTest assertEquals("6 a=b\n", new String(data, 512, 6, CharsetNames.UTF_8)); } + @Test public void testPaxHeadersWithLength99() throws Exception { Map<String, String> m = new HashMap<String, String>(); m.put("a", @@ -167,6 +175,7 @@ public class TarArchiveOutputStreamTest + "012\n", new String(data, 512, 99, CharsetNames.UTF_8)); } + @Test public void testPaxHeadersWithLength101() throws Exception { Map<String, String> m = new HashMap<String, String>(); m.put("a", @@ -201,6 +210,7 @@ public class TarArchiveOutputStreamTest return bos.toByteArray(); } + @Test public void testWriteLongFileNamePosixMode() throws Exception { String n = "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" @@ -225,6 +235,7 @@ public class TarArchiveOutputStreamTest tos.close(); } + @Test public void testOldEntryStarMode() throws Exception { TarArchiveEntry t = new TarArchiveEntry("foo"); t.setSize(Integer.MAX_VALUE); @@ -255,6 +266,7 @@ public class TarArchiveOutputStreamTest closeQuietly(tos); } + @Test public void testOldEntryPosixMode() throws Exception { TarArchiveEntry t = new TarArchiveEntry("foo"); t.setSize(Integer.MAX_VALUE); @@ -287,6 +299,7 @@ public class TarArchiveOutputStreamTest closeQuietly(tos); } + @Test public void testOldEntryError() throws Exception { TarArchiveEntry t = new TarArchiveEntry("foo"); t.setSize(Integer.MAX_VALUE); @@ -301,6 +314,7 @@ public class TarArchiveOutputStreamTest tos.close(); } + @Test public void testWriteNonAsciiPathNamePaxHeader() throws Exception { String n = "\u00e4"; TarArchiveEntry t = new TarArchiveEntry(n); @@ -322,6 +336,7 @@ public class TarArchiveOutputStreamTest tin.close(); } + @Test public void testWriteNonAsciiLinkPathNamePaxHeader() throws Exception { String n = "\u00e4"; TarArchiveEntry t = new TarArchiveEntry("a", TarConstants.LF_LINK); @@ -347,6 +362,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-200" */ + @Test public void testRoundtripWith67CharFileNameGnu() throws Exception { testRoundtripWith67CharFileName(TarArchiveOutputStream.LONGFILE_GNU); } @@ -354,6 +370,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-200" */ + @Test public void testRoundtripWith67CharFileNamePosix() throws Exception { testRoundtripWith67CharFileName(TarArchiveOutputStream.LONGFILE_POSIX); } @@ -379,6 +396,7 @@ public class TarArchiveOutputStreamTest tin.close(); } + @Test public void testWriteLongDirectoryNameErrorMode() throws Exception { String n = "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" @@ -399,6 +417,7 @@ public class TarArchiveOutputStreamTest } } + @Test public void testWriteLongDirectoryNameTruncateMode() throws Exception { String n = "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" @@ -422,6 +441,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-203" */ + @Test public void testWriteLongDirectoryNameGnuMode() throws Exception { testWriteLongDirectoryName(TarArchiveOutputStream.LONGFILE_GNU); } @@ -429,6 +449,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-203" */ + @Test public void testWriteLongDirectoryNamePosixMode() throws Exception { testWriteLongDirectoryName(TarArchiveOutputStream.LONGFILE_POSIX); } @@ -456,6 +477,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-203" */ + @Test public void testWriteNonAsciiDirectoryNamePosixMode() throws Exception { String n = "f\u00f6\u00f6/"; TarArchiveEntry t = new TarArchiveEntry(n); @@ -477,6 +499,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-265" */ + @Test public void testWriteNonAsciiNameWithUnfortunateNamePosixMode() throws Exception { String n = "f\u00f6\u00f6\u00dc"; TarArchiveEntry t = new TarArchiveEntry(n); @@ -498,6 +521,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-237" */ + @Test public void testWriteLongLinkNameErrorMode() throws Exception { String linkname = "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" @@ -519,6 +543,7 @@ public class TarArchiveOutputStreamTest } } + @Test public void testWriteLongLinkNameTruncateMode() throws Exception { String linkname = "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" @@ -543,6 +568,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-237" */ + @Test public void testWriteLongLinkNameGnuMode() throws Exception { testWriteLongLinkName(TarArchiveOutputStream.LONGFILE_GNU); } @@ -550,6 +576,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-237" */ + @Test public void testWriteLongLinkNamePosixMode() throws Exception { testWriteLongLinkName(TarArchiveOutputStream.LONGFILE_POSIX); } @@ -557,7 +584,7 @@ public class TarArchiveOutputStreamTest /** * @see "https://issues.apache.org/jira/browse/COMPRESS-237" */ - public void testWriteLongLinkName(int mode) throws Exception { + private void testWriteLongLinkName(int mode) throws Exception { String linkname = "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789/test"; @@ -580,6 +607,7 @@ public class TarArchiveOutputStreamTest tin.close(); } + @Test public void testPadsOutputToFullBlockLength() throws Exception { File f = File.createTempFile("commons-compress-padding", ".tar"); f.deleteOnExit(); @@ -605,6 +633,7 @@ public class TarArchiveOutputStreamTest * * @throws Exception */ + @Test public void testLongNameMd5Hash() throws Exception { final String longFileName = "a/considerably/longer/file/name/which/forces/use/of/the/long/link/header/which/appears/to/always/use/the/current/time/as/modification/date"; String fname = longFileName; Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java?rev=1660457&r1=1660456&r2=1660457&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java Tue Feb 17 17:40:54 2015 @@ -18,6 +18,8 @@ package org.apache.commons.compress.archivers.zip; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -29,6 +31,7 @@ import java.util.zip.CRC32; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.utils.CharsetNames; +import org.junit.Test; public class UTF8ZipFilesTest extends AbstractTestCase { @@ -37,41 +40,49 @@ public class UTF8ZipFilesTest extends Ab private static final String EURO_FOR_DOLLAR_TXT = "\u20AC_for_Dollar.txt"; private static final String OIL_BARREL_TXT = "\u00D6lf\u00E4sser.txt"; + @Test public void testUtf8FileRoundtripExplicitUnicodeExtra() throws IOException { testFileRoundtrip(CharsetNames.UTF_8, true, true); } + @Test public void testUtf8FileRoundtripNoEFSExplicitUnicodeExtra() throws IOException { testFileRoundtrip(CharsetNames.UTF_8, false, true); } + @Test public void testCP437FileRoundtripExplicitUnicodeExtra() throws IOException { testFileRoundtrip(CP437, false, true); } + @Test public void testASCIIFileRoundtripExplicitUnicodeExtra() throws IOException { testFileRoundtrip(CharsetNames.US_ASCII, false, true); } + @Test public void testUtf8FileRoundtripImplicitUnicodeExtra() throws IOException { testFileRoundtrip(CharsetNames.UTF_8, true, false); } + @Test public void testUtf8FileRoundtripNoEFSImplicitUnicodeExtra() throws IOException { testFileRoundtrip(CharsetNames.UTF_8, false, false); } + @Test public void testCP437FileRoundtripImplicitUnicodeExtra() throws IOException { testFileRoundtrip(CP437, false, false); } + @Test public void testASCIIFileRoundtripImplicitUnicodeExtra() throws IOException { testFileRoundtrip(CharsetNames.US_ASCII, false, false); @@ -83,6 +94,7 @@ public class UTF8ZipFilesTest extends Ab * 7-ZIP doesn't use EFS for strings that can be encoded in CP437 * - which is true for OIL_BARREL_TXT. */ + @Test public void testRead7ZipArchive() throws IOException { File archive = getFile("utf8-7zip-test.zip"); ZipFile zf = null; @@ -96,6 +108,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testRead7ZipArchiveForStream() throws IOException { FileInputStream archive = new FileInputStream(getFile("utf8-7zip-test.zip")); @@ -116,6 +129,7 @@ public class UTF8ZipFilesTest extends Ab * WinZIP created archive, uses Unicode Extra Fields but only in * the central directory. */ + @Test public void testReadWinZipArchive() throws IOException { File archive = getFile("utf8-winzip-test.zip"); ZipFile zf = null; @@ -141,6 +155,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testReadWinZipArchiveForStream() throws IOException { FileInputStream archive = new FileInputStream(getFile("utf8-winzip-test.zip")); @@ -157,6 +172,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testZipFileReadsUnicodeFields() throws IOException { File file = File.createTempFile("unicode-test", ".zip"); file.deleteOnExit(); @@ -176,6 +192,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testZipArchiveInputStreamReadsUnicodeFields() throws IOException { File file = File.createTempFile("unicode-test", ".zip"); @@ -193,6 +210,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testRawNameReadFromZipFile() throws IOException { File archive = getFile("utf8-7zip-test.zip"); @@ -205,6 +223,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testRawNameReadFromStream() throws IOException { FileInputStream archive = @@ -365,6 +384,7 @@ public class UTF8ZipFilesTest extends Ab } } + @Test public void testUtf8Interoperability() throws IOException { File file1 = getFile("utf8-7zip-test.zip"); File file2 = getFile("utf8-winzip-test.zip");