You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pe...@apache.org on 2020/08/10 12:39:13 UTC

[commons-compress] branch master updated: COMPRESS-543 : fix for test fails on Windows

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

peterlee 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 0b9dbbc  COMPRESS-543 : fix for test fails on Windows
0b9dbbc is described below

commit 0b9dbbcee3d4dd35e92ccad1c55d5f429c072ae4
Author: PeterAlfredLee <pe...@gmail.com>
AuthorDate: Mon Aug 10 20:34:51 2020 +0800

    COMPRESS-543 : fix for test fails on Windows
---
 src/changes/changes.xml                                 |  4 ++++
 .../compress/archivers/zip/UTF8ZipFilesTest.java        | 17 +++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 42d14ea..bb1dc9a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -169,6 +169,10 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="update" date="2020-07-23" due-to="Dependabot" dev="ggregory">
         Update GitHub actions/checkout from v1 to v2.3.1 #114.
       </action>
+      <action issue="COMPRESS-543" type="fix" date="2020-08-10" due-to="wulf2333" dev="PeterLee">
+        Fix for test fails on Windows. The tests are failing because the
+        default charset is not UTF-8.
+      </action>
     </release>
     <release version="1.20" date="2020-02-08"
              description="Release 1.20">
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
index d1ac599..7c0b88b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Enumeration;
 import java.util.zip.CRC32;
@@ -135,7 +136,13 @@ public class UTF8ZipFilesTest extends AbstractTestCase {
         final File archive = getFile("utf8-winzip-test.zip");
         ZipFile zf = null;
         try {
-            zf = new ZipFile(archive, null, true);
+            // fix for test fails on Windows with default charset that is not UTF-8
+            String encoding = null;
+            if (Charset.defaultCharset() != StandardCharsets.UTF_8) {
+                encoding = StandardCharsets.UTF_8.name();
+            }
+
+            zf = new ZipFile(archive, encoding, true);
             assertCanRead(zf, ASCII_TXT);
             assertCanRead(zf, EURO_FOR_DOLLAR_TXT);
             assertCanRead(zf, OIL_BARREL_TXT);
@@ -162,7 +169,13 @@ public class UTF8ZipFilesTest extends AbstractTestCase {
             new FileInputStream(getFile("utf8-winzip-test.zip"));
         ZipArchiveInputStream zi = null;
         try {
-            zi = new ZipArchiveInputStream(archive, null, true);
+            // fix for test fails on Windows with default charset that is not UTF-8
+            String encoding = null;
+            if (Charset.defaultCharset() != StandardCharsets.UTF_8) {
+                encoding = StandardCharsets.UTF_8.name();
+            }
+
+            zi = new ZipArchiveInputStream(archive, encoding, true);
             assertEquals(EURO_FOR_DOLLAR_TXT, zi.getNextEntry().getName());
             assertEquals(OIL_BARREL_TXT, zi.getNextEntry().getName());
             assertEquals(ASCII_TXT, zi.getNextEntry().getName());