commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1654901 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
Date Mon, 26 Jan 2015 21:52:28 GMT
Author: krosenvold
Date: Mon Jan 26 21:52:27 2015
New Revision: 1654901

URL: http://svn.apache.org/r1654901
Log:
Avoid 1:1 binary comparison because timestamps will occasionaly vary

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java

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=1654901&r1=1654900&r2=1654901&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
Mon Jan 26 21:52:27 2015
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.io.InputStream; 	
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.zip.ZipEntry;
 
@@ -403,15 +404,37 @@ public final class ZipTestCase extends A
 
     private void assertSameFileContents(File expectedFile, File actualFile) throws IOException
{
         int size = (int) Math.max(expectedFile.length(), actualFile.length());
-        byte[] expected = new byte[size];
-        byte[] actual = new byte[size];
-        final FileInputStream expectedIs = new FileInputStream(expectedFile);
-        final FileInputStream actualIs = new FileInputStream(actualFile);
-        IOUtils.readFully(expectedIs, expected);
-        IOUtils.readFully(actualIs, actual);
-        expectedIs.close();
-        actualIs.close();
-        Assert.assertArrayEquals(expected, actual);
+        ZipFile expected = new ZipFile(expectedFile);
+        ZipFile actual = new ZipFile(actualFile);
+        byte[] expectedBuf = new byte[size];
+        byte[] actualBuf = new byte[size];
+
+        Enumeration<ZipArchiveEntry> actualInOrder = actual.getEntriesInPhysicalOrder();
+        Enumeration<ZipArchiveEntry> expectedInOrder = expected.getEntriesInPhysicalOrder();
+
+        while (actualInOrder.hasMoreElements()){
+            ZipArchiveEntry actualElement = actualInOrder.nextElement();
+            ZipArchiveEntry expectedElement = expectedInOrder.nextElement();
+            assertEquals( expectedElement.getName(), actualElement.getName());
+            assertEquals( expectedElement.getMethod(), actualElement.getMethod());
+            assertEquals( expectedElement.getGeneralPurposeBit(), actualElement.getGeneralPurposeBit());
+            assertEquals( expectedElement.getCrc(), actualElement.getCrc());
+            assertEquals( expectedElement.getCompressedSize(), actualElement.getCompressedSize());
+            assertEquals( expectedElement.getSize(), actualElement.getSize());
+            assertEquals( expectedElement.getExternalAttributes(), actualElement.getExternalAttributes());
+            assertEquals( expectedElement.getInternalAttributes(), actualElement.getInternalAttributes());
+
+            InputStream actualIs = actual.getInputStream(actualElement);
+            InputStream expectedIs = expected.getInputStream(expectedElement);
+            IOUtils.readFully(expectedIs, expectedBuf);
+            IOUtils.readFully(actualIs, actualBuf);
+            expectedIs.close();
+            actualIs.close();
+            Assert.assertArrayEquals(expectedBuf, actualBuf); // Buffers are larger than
payload. dont care
+        }
+
+        expected.close();
+        actual.close();
     }
 
 



Mime
View raw message