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 2c022b98c62a084e86f1286634c7dd5a28928cd7 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu May 5 14:29:10 2022 -0400 Fix broken tests. --- .../apache/commons/compress/archivers/ZipTestCase.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 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 2ed7b48a..e4f3ead3 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java +++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java @@ -18,12 +18,13 @@ */ package org.apache.commons.compress.archivers; -import static java.nio.charset.StandardCharsets.*; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -690,12 +691,12 @@ public final class ZipTestCase extends AbstractTestCase { @Test public void buildSplitZipWithTooSmallSizeThrowsException() throws IOException { - new ZipArchiveOutputStream(File.createTempFile("temp", "zip"), 64 * 1024 - 1); + assertThrows(IllegalArgumentException.class, () -> new ZipArchiveOutputStream(File.createTempFile("temp", "zip"), 64 * 1024 - 1)); } @Test public void buildSplitZipWithTooLargeSizeThrowsException() throws IOException { - new ZipArchiveOutputStream(File.createTempFile("temp", "zip"), 4294967295L + 1); + assertThrows(IllegalArgumentException.class, () -> new ZipArchiveOutputStream(File.createTempFile("temp", "zip"), 4294967295L + 1)); } @Test @@ -710,7 +711,13 @@ public final class ZipTestCase extends AbstractTestCase { final File sameNameFile = new File(dir, "splitZip.z01"); sameNameFile.createNewFile(); - addFilesToZip(zipArchiveOutputStream, directoryToZip); + assertThrows(IOException.class, () -> addFilesToZip(zipArchiveOutputStream, directoryToZip)); + } catch (Exception e) { + // Ignore: + // java.io.IOException: This archive contains unclosed entries. + // at org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.finish(ZipArchiveOutputStream.java:563) + // at org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.close(ZipArchiveOutputStream.java:1119) + // at org.apache.commons.compress.archivers.ZipTestCase.buildSplitZipWithSegmentAlreadyExistThrowsException(ZipTestCase.java:715) } } @@ -857,8 +864,9 @@ public final class ZipTestCase extends AbstractTestCase { zipArchiveOutputStream.putArchiveEntry(zipArchiveEntry); try (final InputStream input = Files.newInputStream(fileToAdd.toPath())) { IOUtils.copy(input, zipArchiveOutputStream); + } finally { + zipArchiveOutputStream.closeArchiveEntry(); } - zipArchiveOutputStream.closeArchiveEntry(); } }