commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r760826 - in /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress: ArchiveReadTests.java DetectArchiverTestCase.java
Date Wed, 01 Apr 2009 09:26:48 GMT
Author: sebb
Date: Wed Apr  1 09:26:46 2009
New Revision: 760826

URL: http://svn.apache.org/viewvc?rev=760826&view=rev
Log:
Move Archive read tests to separate class so can use suites to name the tests

Added:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java
  (with props)
Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java?rev=760826&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java
(added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java
Wed Apr  1 09:26:46 2009
@@ -0,0 +1,104 @@
+/*
+ * 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;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.compress.archivers.ArchiveException;
+
+/**
+ * Test that can read various archive file examples.
+ * 
+ * This is a very simple implementation.
+ * 
+ * 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.
+ */
+public class ArchiveReadTests extends AbstractTestCase {
+    
+    final static ClassLoader classLoader = ArchiveReadTests.class.getClassLoader();
+
+    private File file;
+    private static ArrayList fileList = new ArrayList();
+    
+    public ArchiveReadTests(String name) {
+        super(name);
+    }
+    
+    private ArchiveReadTests(String name, File file){
+        super(name);
+        this.file = file;
+    }
+    
+    public static TestSuite suite() throws IOException{
+        TestSuite suite = new TestSuite("ArchiveReadTests");
+        File arcdir =new File(classLoader.getResource("archives").getFile());
+        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("#")){
+                continue;
+            }
+            String []fields = line.split(" ");
+            fileList.add(fields[1]);
+        }
+        br.close();
+        File[]files=arcdir.listFiles();
+        for (int i=0; i<files.length; i++){
+            final File file = files[i];
+            if (file.getName().endsWith(".txt")){
+                continue;
+            }
+            // Cannot handle these tar files yet 
+            if (file.getName().equals("SunOS_cAEf.tar")
+             || file.getName().equals("FreeBSD_pax.tar")
+             || file.getName().equals("SunOS_cEf.tar")){
+                continue;
+            }
+            // Appears to be the only way to give the test a variable name
+            TestSuite namedSuite = new TestSuite(file.getName());
+            Test test = new ArchiveReadTests("testArchive", file);
+            namedSuite.addTest(test);
+            suite.addTest(namedSuite);
+        }        
+        return suite;
+    }
+    
+    public void testArchive() throws Exception{
+        ArrayList expected=(ArrayList) fileList.clone();
+        try {
+           checkArchiveContent(file, expected);
+        } catch (ArchiveException e) {
+            fail("Problem checking "+file);
+        }
+    }
+}

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ArchiveReadTests.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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=760826&r1=760825&r2=760826&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
Wed Apr  1 09:26:46 2009
@@ -19,13 +19,10 @@
 package org.apache.commons.compress;
 
 import java.io.BufferedInputStream;
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.net.URL;
-import java.util.ArrayList;
 
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
@@ -35,6 +32,10 @@
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 
 public final class DetectArchiverTestCase extends AbstractTestCase {
+    public DetectArchiverTestCase(String name) {
+        super(name);
+    }
+
     final ClassLoader classLoader = getClass().getClassLoader();
 
     public void testDetection() throws Exception {
@@ -75,45 +76,6 @@
                        new File(rsc.getFile()))));
     }
     
-    // TODO move into separate class and create suite with one file per test
-    // Scan list of archives in resources/archives directory
-    public void testArchives() throws Exception{
-        File arcdir =new File(classLoader.getResource("archives").getFile());
-        assertTrue(arcdir.exists());
-        File listing= new File(arcdir,"files.txt");
-        assertTrue("files.txt is readable",listing.canRead());
-        BufferedReader br = new BufferedReader(new FileReader(listing));
-        final ArrayList fileList = new ArrayList();
-        String line;
-        while ((line=br.readLine())!=null){
-            if (line.startsWith("#")){
-                continue;
-            }
-            String []fields = line.split(" ");
-            fileList.add(fields[1]);
-        }
-        br.close();
-        File[]files=arcdir.listFiles();
-        for (int i=0; i<files.length; i++){
-            final File file = files[i];
-            if (file.getName().endsWith(".txt")){
-                continue;
-            }
-            // Cannot handle these tar files yet 
-            if (file.getName().equals("SunOS_cAEf.tar")
-             || file.getName().equals("FreeBSD_pax.tar")
-             || file.getName().equals("SunOS_cEf.tar")){
-                continue;
-            }
-            ArrayList expected=(ArrayList) fileList.clone();
-            try {
-               checkArchiveContent(file, expected);
-            } catch (ArchiveException e) {
-                fail("Problem checking "+file);
-            }
-        }
-    }
-
     // Check that the empty archives created by the code are readable
     
     // Not possible to detect empty "ar" archive as it is completely empty



Mime
View raw message