commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r759813 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
Date Mon, 30 Mar 2009 00:54:55 GMT
Author: sebb
Date: Mon Mar 30 00:54:55 2009
New Revision: 759813

URL: http://svn.apache.org/viewvc?rev=759813&view=rev
Log:
Check can add a file to an empty archive

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java?rev=759813&r1=759812&r2=759813&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
Mon Mar 30 00:54:55 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.commons.compress.changes;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -595,4 +594,47 @@
      */
     public void testAddMoveDelete() throws Exception {
     }
+    
+    /**
+     * Check can add a file to an empty archive.
+     * 
+     * @throws Exception
+     */
+    public void testAddToEmptyArchive() throws Exception {
+        File input = this.createEmptyArchive("zip");
+
+        ArchiveOutputStream out = null;
+        ArchiveInputStream ais = null;
+        InputStream is = null;
+        File result = File.createTempFile("test", ".zip");
+        result.deleteOnExit();
+        ChangeSet changes = new ChangeSet();
+        try {
+
+            is = new FileInputStream(input);
+            ais = factory.createArchiveInputStream("zip", is);
+
+            out = factory.createArchiveOutputStream("zip",
+                    new FileOutputStream(result));
+
+            final File file1 = getFile("test.txt");
+            ArchiveEntry entry = new ZipArchiveEntry("bla/test.txt");
+            changes.add(entry, new FileInputStream(file1));
+            archiveList.add("bla/test.txt");
+            changes.perform(ais, out);
+            is.close();
+
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+            if (ais != null) {
+                ais.close(); // will close is 
+            } else if (is != null){
+                is.close();
+            }
+        }
+
+        this.checkArchiveContent(result, archiveList);
+    }
 }



Mime
View raw message