This is an automated email from the ASF dual-hosted git repository.

bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 1221cd8  remove shaded commons-io used in tests, plug some test leaks
1221cd8 is described below

commit 1221cd85369e270824f7c105781d0f2112a522e2
Author: Stefan Bodewig <[email protected]>
AuthorDate: Fri Jan 24 19:59:57 2020 +0100

    remove shaded commons-io used in tests, plug some test leaks
---
 .../commons/compress/archivers/ZipTestCase.java    |  4 +-
 .../compress/archivers/tar/SparseFilesTest.java    | 76 +++++++++-----------
 .../archivers/zip/ZipArchiveInputStreamTest.java   | 81 ++++++++++++----------
 3 files changed, 81 insertions(+), 80 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java 
b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
index c45db11..a324524 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
@@ -680,8 +680,8 @@ public final class ZipTestCase extends AbstractTestCase {
                 // compare all files one by one
                 File fileToCompare = new File(entry.getName());
                 try (InputStream inputStreamToCompare = new 
FileInputStream(fileToCompare)) {
-                    Assert.assertTrue(
-                        
shaded.org.apache.commons.io.IOUtils.contentEquals(splitInputStream, 
inputStreamToCompare));
+                    assertArrayEquals(IOUtils.toByteArray(splitInputStream),
+                        IOUtils.toByteArray(inputStreamToCompare));
                 }
                 filesCount++;
             }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java 
b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index 6056feb..24218c2 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -21,9 +21,9 @@ package org.apache.commons.compress.archivers.tar;
 import static org.junit.Assert.*;
 
 import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.utils.IOUtils;
 import org.junit.Assert;
 import org.junit.Test;
-import shaded.org.apache.commons.io.IOUtils;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -92,36 +92,30 @@ public class SparseFilesTest extends AbstractTestCase {
 
         final File oldGNUSparseTar = getFile("oldgnu_sparse.tar");
         final File paxGNUSparseTar = getFile("pax_gnu_sparse.tar");
-        TarArchiveInputStream oldGNUSparseInputStream = null;
-        TarArchiveInputStream paxGNUSparseInputStream = null;
-        try {
+        try (TarArchiveInputStream paxGNUSparseInputStream = new 
TarArchiveInputStream(new FileInputStream(paxGNUSparseTar))) {
+
             // compare between old GNU and PAX 0.0
-            oldGNUSparseInputStream = new TarArchiveInputStream(new 
FileInputStream(oldGNUSparseTar));
-            oldGNUSparseInputStream.getNextTarEntry();
-            paxGNUSparseInputStream = new TarArchiveInputStream(new 
FileInputStream(paxGNUSparseTar));
             paxGNUSparseInputStream.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(oldGNUSparseInputStream, 
paxGNUSparseInputStream));
+            try (TarArchiveInputStream oldGNUSparseInputStream = new 
TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) {
+                oldGNUSparseInputStream.getNextTarEntry();
+                assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream),
+                    IOUtils.toByteArray(paxGNUSparseInputStream));
+            }
 
             // compare between old GNU and PAX 0.1
-            oldGNUSparseInputStream.close();
-            oldGNUSparseInputStream = new TarArchiveInputStream(new 
FileInputStream(oldGNUSparseTar));
-            oldGNUSparseInputStream.getNextTarEntry();
             paxGNUSparseInputStream.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(oldGNUSparseInputStream, 
paxGNUSparseInputStream));
+            try (TarArchiveInputStream oldGNUSparseInputStream = new 
TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) {
+                oldGNUSparseInputStream.getNextTarEntry();
+                assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream),
+                    IOUtils.toByteArray(paxGNUSparseInputStream));
+            }
 
             // compare between old GNU and PAX 1.0
-            oldGNUSparseInputStream.close();
-            oldGNUSparseInputStream = new TarArchiveInputStream(new 
FileInputStream(oldGNUSparseTar));
-            oldGNUSparseInputStream.getNextTarEntry();
             paxGNUSparseInputStream.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(oldGNUSparseInputStream, 
paxGNUSparseInputStream));
-        } finally {
-            if (oldGNUSparseInputStream != null) {
-                oldGNUSparseInputStream.close();
-            }
-
-            if (paxGNUSparseInputStream != null) {
-                paxGNUSparseInputStream.close();
+            try (TarArchiveInputStream oldGNUSparseInputStream = new 
TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) {
+                oldGNUSparseInputStream.getNextTarEntry();
+                assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream),
+                    IOUtils.toByteArray(paxGNUSparseInputStream));
             }
         }
     }
@@ -136,7 +130,8 @@ public class SparseFilesTest extends AbstractTestCase {
         try (InputStream sparseFileInputStream = 
extractTarAndGetInputStream(file, "sparsefile");
              TarArchiveInputStream tin = new TarArchiveInputStream(new 
FileInputStream(file))) {
             tin.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(tin, 
sparseFileInputStream));
+            assertArrayEquals(IOUtils.toByteArray(tin),
+                IOUtils.toByteArray(sparseFileInputStream));
         }
     }
 
@@ -151,7 +146,8 @@ public class SparseFilesTest extends AbstractTestCase {
              TarArchiveInputStream tin = new TarArchiveInputStream(new 
FileInputStream(file))) {
             final TarArchiveEntry ae = tin.getNextTarEntry();
 
-            Assert.assertTrue(IOUtils.contentEquals(tin, 
sparseFileInputStream));
+            assertArrayEquals(IOUtils.toByteArray(tin),
+                IOUtils.toByteArray(sparseFileInputStream));
 
             List<TarArchiveStructSparse> sparseHeaders = ae.getSparseHeaders();
             assertEquals(7, sparseHeaders.size());
@@ -186,30 +182,26 @@ public class SparseFilesTest extends AbstractTestCase {
         }
 
         final File file = getFile("pax_gnu_sparse.tar");
-        InputStream sparseFileInputStream = null;
-        TarArchiveInputStream tin = null;
-        try {
-            sparseFileInputStream = extractTarAndGetInputStream(file, 
"sparsefile-0.0");
-            tin = new TarArchiveInputStream(new FileInputStream(file));
+        try (TarArchiveInputStream tin = new TarArchiveInputStream(new 
FileInputStream(file))) {
+
             tin.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(tin, 
sparseFileInputStream));
+            try (InputStream sparseFileInputStream = 
extractTarAndGetInputStream(file, "sparsefile-0.0")) {
+                assertArrayEquals(IOUtils.toByteArray(tin),
+                    IOUtils.toByteArray(sparseFileInputStream));
+            }
 
             // TODO : it's wired that I can only get a 0 size sparsefile-0.1 
on my Ubuntu 16.04
             //        using "tar -xf pax_gnu_sparse.tar"
-            sparseFileInputStream = extractTarAndGetInputStream(file, 
"sparsefile-0.0");
-            tin.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(tin, 
sparseFileInputStream));
-
-            sparseFileInputStream = extractTarAndGetInputStream(file, 
"sparsefile-1.0");
             tin.getNextTarEntry();
-            Assert.assertTrue(IOUtils.contentEquals(tin, 
sparseFileInputStream));
-        } finally {
-            if (sparseFileInputStream != null) {
-                sparseFileInputStream.close();
+            try (InputStream sparseFileInputStream = 
extractTarAndGetInputStream(file, "sparsefile-0.0")) {
+                assertArrayEquals(IOUtils.toByteArray(tin),
+                    IOUtils.toByteArray(sparseFileInputStream));
             }
 
-            if (tin != null) {
-                tin.close();
+            tin.getNextTarEntry();
+            try (InputStream sparseFileInputStream = 
extractTarAndGetInputStream(file, "sparsefile-1.0")) {
+                assertArrayEquals(IOUtils.toByteArray(tin),
+                    IOUtils.toByteArray(sparseFileInputStream));
             }
         }
     }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index f108878..def1463 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -601,57 +601,66 @@ public class ZipArchiveInputStreamTest {
     @Test
     public void testSplitZipCreatedByZip() throws IOException {
         File lastFile = 
getFile("COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.zip");
-        SeekableByteChannel channel = 
ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
-        InputStream inputStream = Channels.newInputStream(channel);
-        ZipArchiveInputStream splitInputStream = new 
ZipArchiveInputStream(inputStream, ZipEncodingHelper.UTF8, true, false, true);
-
-        File fileToCompare = 
getFile("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip.zip");
-        ZipArchiveInputStream inputStreamToCompare = new 
ZipArchiveInputStream(new FileInputStream(fileToCompare), 
ZipEncodingHelper.UTF8, true, false, true);
-
-        ArchiveEntry entry;
-        while((entry = splitInputStream.getNextEntry()) != null && 
inputStreamToCompare.getNextEntry() != null) {
-            if(entry.isDirectory()) {
-                continue;
+        try (SeekableByteChannel channel = 
ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
+             InputStream inputStream = Channels.newInputStream(channel);
+             ZipArchiveInputStream splitInputStream = new 
ZipArchiveInputStream(inputStream, ZipEncodingHelper.UTF8, true, false, true)) {
+
+            File fileToCompare = 
getFile("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip.zip");
+            try (ZipArchiveInputStream inputStreamToCompare = new 
ZipArchiveInputStream(new FileInputStream(fileToCompare), 
ZipEncodingHelper.UTF8, true, false, true)) {
+
+                ArchiveEntry entry;
+                while((entry = splitInputStream.getNextEntry()) != null && 
inputStreamToCompare.getNextEntry() != null) {
+                    if(entry.isDirectory()) {
+                        continue;
+                    }
+                    assertArrayEquals(IOUtils.toByteArray(splitInputStream),
+                         IOUtils.toByteArray(inputStreamToCompare));
+                }
             }
-            
Assert.assertTrue(shaded.org.apache.commons.io.IOUtils.contentEquals(splitInputStream,
 inputStreamToCompare));
         }
     }
 
     @Test
     public void testSplitZipCreatedByZipOfZip64() throws IOException {
         File lastFile = 
getFile("COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.zip");
-        SeekableByteChannel channel = 
ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
-        InputStream inputStream = Channels.newInputStream(channel);
-        ZipArchiveInputStream splitInputStream = new 
ZipArchiveInputStream(inputStream, ZipEncodingHelper.UTF8, true, false, true);
-
-        File fileToCompare = 
getFile("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip_zip64.zip");
-        ZipArchiveInputStream inputStreamToCompare = new 
ZipArchiveInputStream(new FileInputStream(fileToCompare), 
ZipEncodingHelper.UTF8, true, false, true);
-
-        ArchiveEntry entry;
-        while((entry = splitInputStream.getNextEntry()) != null && 
inputStreamToCompare.getNextEntry() != null) {
-            if(entry.isDirectory()) {
-                continue;
+        try (SeekableByteChannel channel = 
ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
+             InputStream inputStream = Channels.newInputStream(channel);
+             ZipArchiveInputStream splitInputStream = new 
ZipArchiveInputStream(inputStream, ZipEncodingHelper.UTF8, true, false, true)) {
+
+            File fileToCompare = 
getFile("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip_zip64.zip");
+            try (ZipArchiveInputStream inputStreamToCompare = new 
ZipArchiveInputStream(new FileInputStream(fileToCompare), 
ZipEncodingHelper.UTF8, true, false, true)) {
+
+                ArchiveEntry entry;
+                while((entry = splitInputStream.getNextEntry()) != null && 
inputStreamToCompare.getNextEntry() != null) {
+                    if(entry.isDirectory()) {
+                        continue;
+                    }
+                    assertArrayEquals(IOUtils.toByteArray(splitInputStream),
+                        IOUtils.toByteArray(inputStreamToCompare));
+                }
             }
-            
Assert.assertTrue(shaded.org.apache.commons.io.IOUtils.contentEquals(splitInputStream,
 inputStreamToCompare));
         }
     }
 
     @Test
     public void testSplitZipCreatedByWinrar() throws IOException {
         File lastFile = 
getFile("COMPRESS-477/split_zip_created_by_winrar/split_zip_created_by_winrar.zip");
-        SeekableByteChannel channel = 
ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
-        InputStream inputStream = Channels.newInputStream(channel);
-        ZipArchiveInputStream splitInputStream = new 
ZipArchiveInputStream(inputStream, ZipEncodingHelper.UTF8, true, false, true);
-
-        File fileToCompare = 
getFile("COMPRESS-477/split_zip_created_by_winrar/zip_to_compare_created_by_winrar.zip");
-        ZipArchiveInputStream inputStreamToCompare = new 
ZipArchiveInputStream(new FileInputStream(fileToCompare), 
ZipEncodingHelper.UTF8, true, false, true);
-
-        ArchiveEntry entry;
-        while((entry = splitInputStream.getNextEntry()) != null && 
inputStreamToCompare.getNextEntry() != null) {
-            if(entry.isDirectory()) {
-                continue;
+        try (SeekableByteChannel channel = 
ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
+             InputStream inputStream = Channels.newInputStream(channel);
+             ZipArchiveInputStream splitInputStream = new 
ZipArchiveInputStream(inputStream, ZipEncodingHelper.UTF8, true, false, true)) {
+
+            File fileToCompare = 
getFile("COMPRESS-477/split_zip_created_by_winrar/zip_to_compare_created_by_winrar.zip");
+            try (ZipArchiveInputStream inputStreamToCompare = new 
ZipArchiveInputStream(new FileInputStream(fileToCompare), 
ZipEncodingHelper.UTF8, true, false, true)) {
+
+                ArchiveEntry entry;
+                while((entry = splitInputStream.getNextEntry()) != null && 
inputStreamToCompare.getNextEntry() != null) {
+                    if(entry.isDirectory()) {
+                        continue;
+                    }
+                    assertArrayEquals(IOUtils.toByteArray(splitInputStream),
+                        IOUtils.toByteArray(inputStreamToCompare));
+                }
             }
-            
Assert.assertTrue(shaded.org.apache.commons.io.IOUtils.contentEquals(splitInputStream,
 inputStreamToCompare));
         }
     }
 

Reply via email to