You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/04/07 12:24:40 UTC

(commons-compress) branch master updated (cb3c3409c -> 3c2c3e70a)

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

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


    from cb3c3409c Fix Javadoc typo
     new c26345825 Fix test method names
     new 3c2c3e70a Add tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/commons/compress/archivers/ZipTest.java | 35 ++++++++++++++++++++++
 .../compress/archivers/sevenz/SevenZFileTest.java  | 27 +++++++++++++++--
 2 files changed, 60 insertions(+), 2 deletions(-)


(commons-compress) 02/02: Add tests

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3c2c3e70a135b4b5fbabe8ce79543007c17f7d0d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Apr 7 08:24:34 2026 -0400

    Add tests
---
 .../apache/commons/compress/archivers/ZipTest.java | 35 ++++++++++++++++++++++
 .../compress/archivers/sevenz/SevenZFileTest.java  | 23 ++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
index 9e39f9305..a130c091c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
@@ -59,6 +59,7 @@
 import org.apache.commons.compress.utils.InputStreamStatistics;
 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.channels.ByteArraySeekableByteChannel;
 import org.junit.jupiter.api.Test;
 
 public final class ZipTest extends AbstractTest {
@@ -770,6 +771,40 @@ void testZipArchiveCreation() throws Exception {
      */
     @Test
     void testZipArchiveCreationInMemory() throws Exception {
+        final byte[] file1Contents = readAllBytes("test1.xml");
+        final byte[] file2Contents = readAllBytes("test2.xml");
+        final List<byte[]> results = new ArrayList<>();
+        try (ByteArraySeekableByteChannel channel = new ByteArraySeekableByteChannel()) {
+            try (ZipArchiveOutputStream os = new ZipArchiveOutputStream(channel)) {
+                os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
+                os.write(file1Contents);
+                os.closeArchiveEntry();
+
+                os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml"));
+                os.write(file2Contents);
+                os.closeArchiveEntry();
+            }
+            // Unarchive the same
+            try (ZipArchiveInputStream inputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", new ByteArrayInputStream(channel.array()))) {
+                ZipArchiveEntry entry;
+                while ((entry = inputStream.getNextEntry()) != null) {
+                    final byte[] result = new byte[(int) entry.getSize()];
+                    IOUtils.readFully(inputStream, result);
+                    results.add(result);
+                }
+            }
+        }
+        assertArrayEquals(results.get(0), file1Contents);
+        assertArrayEquals(results.get(1), file2Contents);
+    }
+
+    /**
+     * Archives 2 files and unarchives it again. If the file contents of result and source is the same, it looks like the operations have worked
+     *
+     * @throws Exception
+     */
+    @Test
+    void testZipArchiveCreationInMemoryDepreacted() throws Exception {
         final byte[] file1Contents = readAllBytes("test1.xml");
         final byte[] file2Contents = readAllBytes("test2.xml");
         final List<byte[]> results = new ArrayList<>();
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index d6a9ac379..7bcedee00 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -62,6 +62,7 @@
 import org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel;
 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.channels.ByteArraySeekableByteChannel;
 import org.apache.commons.io.input.ChecksumInputStream;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -337,6 +338,14 @@ void test7zDeflateUnarchive() throws Exception {
 
     @Test
     void test7zMultiVolumeUnarchive() throws Exception {
+        try (SevenZFile sevenZFile = SevenZFile.builder()
+                .setChannel(MultiReadOnlySeekableByteChannel.forFiles(getFile("bla-multi.7z.001"), getFile("bla-multi.7z.002"))).get()) {
+            test7zUnarchive(sevenZFile, SevenZMethod.LZMA2);
+        }
+    }
+
+    @Test
+    void test7zMultiVolumeUnarchiveDeprecated() throws Exception {
         try (SevenZFile sevenZFile = SevenZFile.builder()
                 .setSeekableByteChannel(MultiReadOnlySeekableByteChannel.forFiles(getFile("bla-multi.7z.001"), getFile("bla-multi.7z.002"))).get()) {
             test7zUnarchive(sevenZFile, SevenZMethod.LZMA2);
@@ -539,6 +548,20 @@ void testGetDefaultName() throws Exception {
 
     @Test
     void testGetEntriesOfUnarchiveInMemory() throws IOException {
+        final byte[] data = readAllBytes("bla.7z");
+        try (SevenZFile sevenZFile = SevenZFile.builder().setChannel(ByteArraySeekableByteChannel.wrap(data)).get()) {
+            final Iterable<SevenZArchiveEntry> entries = sevenZFile.getEntries();
+            final Iterator<SevenZArchiveEntry> iter = entries.iterator();
+            SevenZArchiveEntry entry = iter.next();
+            assertEquals("test1.xml", entry.getName());
+            entry = iter.next();
+            assertEquals("test2.xml", entry.getName());
+            assertFalse(iter.hasNext());
+        }
+    }
+
+    @Test
+    void testGetEntriesOfUnarchiveInMemoryDeprecacted() throws IOException {
         final byte[] data = readAllBytes("bla.7z");
         try (SevenZFile sevenZFile = SevenZFile.builder().setSeekableByteChannel(new SeekableInMemoryByteChannel(data)).get()) {
             final Iterable<SevenZArchiveEntry> entries = sevenZFile.getEntries();


(commons-compress) 01/02: Fix test method names

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c26345825455236b4131e10e9782e08fddd55d87
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Apr 7 08:20:22 2026 -0400

    Fix test method names
---
 .../org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index f3c3bf1a5..d6a9ac379 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -538,7 +538,7 @@ void testGetDefaultName() throws Exception {
     }
 
     @Test
-    void testGetEntriesOfUnarchiveInMemoryTest() throws IOException {
+    void testGetEntriesOfUnarchiveInMemory() throws IOException {
         final byte[] data = readAllBytes("bla.7z");
         try (SevenZFile sevenZFile = SevenZFile.builder().setSeekableByteChannel(new SeekableInMemoryByteChannel(data)).get()) {
             final Iterable<SevenZArchiveEntry> entries = sevenZFile.getEntries();
@@ -552,7 +552,7 @@ void testGetEntriesOfUnarchiveInMemoryTest() throws IOException {
     }
 
     @Test
-    void testGetEntriesOfUnarchiveTest() throws IOException {
+    void testGetEntriesOfUnarchive() throws IOException {
         try (SevenZFile sevenZFile = getSevenZFile("bla.7z")) {
             final Iterable<SevenZArchiveEntry> entries = sevenZFile.getEntries();
             final Iterator<SevenZArchiveEntry> iter = entries.iterator();