commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1362302 - in /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress: ./ archivers/ar/ archivers/memory/ archivers/tar/ archivers/zip/
Date Mon, 16 Jul 2012 22:48:44 GMT
Author: sebb
Date: Mon Jul 16 22:48:43 2012
New Revision: 1362302

URL: http://svn.apache.org/viewvc?rev=1362302&view=rev
Log:
Ensure resources are closed

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/archivers/ar/ArArchiveOutputStreamTest.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveTestCase.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.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/ZipArchiveEntryTest.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=1362302&r1=1362301&r2=1362302&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
Mon Jul 16 22:48:43 2012
@@ -19,6 +19,7 @@
 package org.apache.commons.compress;
 
 import java.io.BufferedInputStream;
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -389,4 +390,14 @@ public abstract class AbstractTestCase e
             fos.close();
         }
     }
+    
+    protected void closeQuietly(Closeable closeable){
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException ignored) {
+                // ignored
+            }
+        }
+    }
 }

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=1362302&r1=1362301&r2=1362302&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
Mon Jul 16 22:48:43 2012
@@ -30,15 +30,17 @@ import org.apache.commons.compress.Abstr
 public class ArArchiveOutputStreamTest extends AbstractTestCase {
 
     public void testLongFileNamesCauseExceptionByDefault() {
+        ArArchiveOutputStream os = null;
         try {
-            ArArchiveOutputStream os =
-                new ArArchiveOutputStream(new ByteArrayOutputStream());
+            os = new ArArchiveOutputStream(new ByteArrayOutputStream());
             ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt",
                                                    0);
             os.putArchiveEntry(ae);
             fail("Expected an exception");
         } catch (IOException ex) {
             assertTrue(ex.getMessage().startsWith("filename too long"));
+        } finally {
+            closeQuietly(os);
         }
     }
 

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveTestCase.java?rev=1362302&r1=1362301&r2=1362302&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveTestCase.java
Mon Jul 16 22:48:43 2012
@@ -48,6 +48,7 @@ public final class MemoryArchiveTestCase
         final ArchiveEntry entry3 = is.getNextEntry();
         assertNull(entry3);
 
+        is.close();
     }
 
 }

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java?rev=1362302&r1=1362301&r2=1362302&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
Mon Jul 16 22:48:43 2012
@@ -38,20 +38,24 @@ public class TarArchiveInputStreamTest {
 
     @Test
     public void readSimplePaxHeader() throws Exception {
-        Map<String, String> headers = new TarArchiveInputStream(null)
+        final TarArchiveInputStream tais = new TarArchiveInputStream(null);
+        Map<String, String> headers = tais
             .parsePaxHeaders(new ByteArrayInputStream("30 atime=1321711775.972059463\n"
                                                       .getBytes(CharsetNames.UTF_8)));
         assertEquals(1, headers.size());
         assertEquals("1321711775.972059463", headers.get("atime"));
+        tais.close();
     }
 
     @Test
     public void readPaxHeaderWithEmbeddedNewline() throws Exception {
-        Map<String, String> headers = new TarArchiveInputStream(null)
+        final TarArchiveInputStream tais = new TarArchiveInputStream(null);
+        Map<String, String> headers = tais
             .parsePaxHeaders(new ByteArrayInputStream("28 comment=line1\nline2\nand3\n"
                                                       .getBytes(CharsetNames.UTF_8)));
         assertEquals(1, headers.size());
         assertEquals("line1\nline2\nand3", headers.get("comment"));
+        tais.close();
     }
 
     @Test
@@ -59,10 +63,12 @@ public class TarArchiveInputStreamTest {
         String ae = "\u00e4";
         String line = "11 path="+ ae + "\n";
         assertEquals(11, line.getBytes(CharsetNames.UTF_8).length);
-        Map<String, String> headers = new TarArchiveInputStream(null)
+        final TarArchiveInputStream tais = new TarArchiveInputStream(null);
+        Map<String, String> headers = tais
             .parsePaxHeaders(new ByteArrayInputStream(line.getBytes(CharsetNames.UTF_8)));
         assertEquals(1, headers.size());
         assertEquals(ae, headers.get("path"));
+        tais.close();
     }
 
     @Test

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=1362302&r1=1362301&r2=1362302&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
Mon Jul 16 22:48:43 2012
@@ -96,6 +96,8 @@ public class TarArchiveOutputStreamTest 
             new TarArchiveInputStream(new ByteArrayInputStream(data));
         TarArchiveEntry e = tin.getNextTarEntry();
         assertEquals(0100000000000L, e.getSize());
+        tin.close();
+        tos.close();
     }
 
     public void testBigNumberPosixMode() throws Exception {
@@ -119,6 +121,8 @@ public class TarArchiveOutputStreamTest 
             new TarArchiveInputStream(new ByteArrayInputStream(data));
         TarArchiveEntry e = tin.getNextTarEntry();
         assertEquals(0100000000000L, e.getSize());
+        tin.close();
+        tos.close();
     }
 
     public void testWriteSimplePaxHeaders() throws Exception {
@@ -181,6 +185,7 @@ public class TarArchiveOutputStreamTest 
         tos.putArchiveEntry(t);
         tos.write(new byte[10 * 1024]);
         tos.closeArchiveEntry();
+        tos.close();
 
         return bos.toByteArray();
     }
@@ -205,6 +210,8 @@ public class TarArchiveOutputStreamTest 
             new TarArchiveInputStream(new ByteArrayInputStream(data));
         TarArchiveEntry e = tin.getNextTarEntry();
         assertEquals(n, e.getName());
+        tin.close();
+        tos.close();
     }
 
     public void testOldEntryStarMode() throws Exception {
@@ -231,6 +238,8 @@ public class TarArchiveOutputStreamTest 
         cal.set(1969, 11, 31, 23, 59, 59);
         cal.set(Calendar.MILLISECOND, 0);
         assertEquals(cal.getTime(), e.getLastModifiedDate());
+        tin.close();
+        tos.close();
     }
 
     public void testOldEntryPosixMode() throws Exception {
@@ -259,6 +268,8 @@ public class TarArchiveOutputStreamTest 
         cal.set(1969, 11, 31, 23, 59, 59);
         cal.set(Calendar.MILLISECOND, 0);
         assertEquals(cal.getTime(), e.getLastModifiedDate());
+        tin.close();
+        tos.close();
     }
 
     public void testOldEntryError() throws Exception {
@@ -272,6 +283,7 @@ public class TarArchiveOutputStreamTest 
             fail("Should have generated RuntimeException");
         } catch (RuntimeException expected) {
         }
+        tos.close();
     }
 
     public void testWriteNonAsciiPathNamePaxHeader() throws Exception {
@@ -292,6 +304,7 @@ public class TarArchiveOutputStreamTest 
             new TarArchiveInputStream(new ByteArrayInputStream(data));
         TarArchiveEntry e = tin.getNextTarEntry();
         assertEquals(n, e.getName());
+        tin.close();
     }
 
     public void testWriteNonAsciiLinkPathNamePaxHeader() throws Exception {
@@ -313,6 +326,7 @@ public class TarArchiveOutputStreamTest 
             new TarArchiveInputStream(new ByteArrayInputStream(data));
         TarArchiveEntry e = tin.getNextTarEntry();
         assertEquals(n, e.getLinkName());
+        tin.close();
     }
 
 }
\ No newline at end of file

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java?rev=1362302&r1=1362301&r2=1362302&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
Mon Jul 16 22:48:43 2012
@@ -204,7 +204,7 @@ public class ZipArchiveEntryTest extends
      * <a href="https://issues.apache.org/jira/browse/COMPRESS-93"
      * >COMPRESS-93</a>.
      */
-    public void testCompressionMethod() {
+    public void testCompressionMethod() throws Exception {
         ZipArchiveOutputStream zos =
             new ZipArchiveOutputStream((java.io.OutputStream) null);
         ZipArchiveEntry entry = new ZipArchiveEntry("foo");
@@ -223,6 +223,7 @@ public class ZipArchiveEntryTest extends
         entry.setMethod(6);
         assertEquals(6, entry.getMethod());
         assertFalse(zos.canWriteEntryData(entry));
+        zos.close();
     }
 
     /**
@@ -238,7 +239,7 @@ public class ZipArchiveEntryTest extends
 
     /**
      * Tests comment's influence on equals comparisons.
-     * @see https://issues.apache.org/jira/browse/COMPRESS-187
+     * @see "https://issues.apache.org/jira/browse/COMPRESS-187"
      */
     public void testNullCommentEqualsEmptyComment() {
         ZipArchiveEntry entry1 = new ZipArchiveEntry("foo");



Mime
View raw message