From 699af2fd9381a436a5e695641c692998b89db58b Mon Sep 17 00:00:00 2001
From: Christoph Gysin <christoph.gysin@gmail.com>
Date: Fri, 31 May 2013 20:10:12 +0300
Subject: [PATCH 1/5] allow creating testsuites over different archives

---
 .../commons/compress/archivers/LongPathTest.java   | 25 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
index 1f951a6..983c215 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
@@ -25,6 +25,8 @@ import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.Test;
@@ -33,6 +35,7 @@ import junit.framework.TestSuite;
 import org.apache.commons.compress.AbstractTestCase;
 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;
 
@@ -44,26 +47,36 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
  */
 public class LongPathTest extends AbstractTestCase {
 
+    private String name;
     private File file;
 
-    private static final ArrayList<String> fileList = new ArrayList<String>();
+    private static final Map<String, ArrayList<String>> fileLists = new HashMap<String, ArrayList<String>>();
 
     public LongPathTest(String name) {
         super(name);
     }
 
-    private LongPathTest(String name, File file){
-        super(name);
+    private LongPathTest(String name, String function, File file){
+        super(function);
+        this.name = name;
         this.file = file;
     }
 
     public static TestSuite suite() throws IOException{
         TestSuite suite = new TestSuite("LongPathTests");
-        File arcdir = getFile("longpath");
+        suite.addTest(createSuite("LongPathTest", "longpath"));
+        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());
         BufferedReader br = new BufferedReader(new FileReader(listing));
+
+        ArrayList<String> fileList = new ArrayList<String>();
         String line;
         while ((line=br.readLine())!=null){
             if (line.startsWith("#")){
@@ -71,6 +84,7 @@ public class LongPathTest extends AbstractTestCase {
             }
             fileList.add(line);
         }
+        fileLists.put(name, fileList);
         br.close();
         File[]files=arcdir.listFiles();
         for (final File file : files) {
@@ -79,7 +93,7 @@ public class LongPathTest extends AbstractTestCase {
             }
             // Appears to be the only way to give the test a variable name
             TestSuite namedSuite = new TestSuite(file.getName());
-            Test test = new LongPathTest("testArchive", file);
+            Test test = new LongPathTest(name, "testArchive", file);
             namedSuite.addTest(test);
             suite.addTest(namedSuite);
         }
@@ -87,6 +101,7 @@ public class LongPathTest extends AbstractTestCase {
     }
 
     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();
         String name = file.getName();
-- 
1.8.3

