commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [5/7] commons-compress git commit: Random coveralls bait.
Date Thu, 06 Jul 2017 07:07:34 GMT
Random coveralls bait.

Signed-off-by: Simon Spero <sesuncedu@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/ffa1c55e
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/ffa1c55e
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/ffa1c55e

Branch: refs/heads/master
Commit: ffa1c55e7f9d8808e4e440effe78e31aa89a4ec1
Parents: 983fcdc
Author: Simon Spero <sesuncedu@gmail.com>
Authored: Sat Jun 24 16:53:26 2017 -0400
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu Jul 6 09:07:16 2017 +0200

----------------------------------------------------------------------
 .../commons/compress/archivers/sevenz/CLI.java  |  2 +-
 .../compress/archivers/zip/AsiExtraField.java   | 16 ++++----
 .../compress/archivers/arj/CoverageTest.java    | 23 +++++++++++
 .../compress/archivers/jar/JarMarkerTest.java   | 39 +++++++++++++++++++
 .../compress/archivers/sevenz/CoverageTest.java | 24 ++++++++++++
 .../compress/archivers/zip/BinaryTreeTest.java  | 24 ++++++++++++
 .../archivers/zip/ExplodeSupportTest.java       | 18 +++++++++
 .../archivers/zip/ExtraFieldUtilsTest.java      | 12 ++++++
 .../archivers/zip/PkWareExtraHeaderTest.java    | 28 +++++++++++++
 .../archivers/zip/StreamCompressorTest.java     | 23 ++++++++---
 .../archivers/zip/ZipClassCoverageTest.java     | 41 ++++++++++++++++++++
 11 files changed, 236 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
index 58e52ee..0db5a42 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
@@ -23,7 +23,6 @@ import java.io.IOException;
 
 public class CLI {
 
-    private static final byte[] BUF = new byte[8192];
 
     private static enum Mode {
         LIST("Analysing") {
@@ -65,6 +64,7 @@ public class CLI {
             }
         },
         EXTRACT("Extracting") {
+            private  final byte[] BUF = new byte[8192];
             @Override
             public void takeAction(final SevenZFile archive, final SevenZArchiveEntry entry)

                 throws IOException {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
index e4afa95..4d8b65c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
@@ -325,13 +325,13 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable
{
 
     @Override
     public Object clone() {
-        try {
-            final AsiExtraField cloned = (AsiExtraField) super.clone();
-            cloned.crc = new CRC32();
-            return cloned;
-        } catch (final CloneNotSupportedException cnfe) {
-            // impossible
-            throw new RuntimeException(cnfe); //NOSONAR
-        }
+        AsiExtraField cloned = new AsiExtraField();
+        cloned.mode = mode;
+        cloned.uid = uid;
+        cloned.gid =gid;
+        cloned.link = link;
+        cloned.dirFlag = dirFlag;
+        cloned.crc = new CRC32();
+        return cloned;
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java b/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java
new file mode 100644
index 0000000..bd394f7
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java
@@ -0,0 +1,23 @@
+package org.apache.commons.compress.archivers.arj;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.commons.compress.archivers.arj.ArjArchiveEntry.HostOs;
+import org.junit.Test;
+
+public class CoverageTest {
+
+    @Test
+    public void testHostOsInstance() {
+        HostOs hostOs = new HostOs();
+        assertNotNull(hostOs);
+    }
+    @Test
+    public void testHeaderInstances() {
+        assertNotNull(new LocalFileHeader.FileTypes());
+        assertNotNull(new LocalFileHeader.Methods());
+        assertNotNull(new LocalFileHeader.Flags());
+        assertNotNull(new MainHeader.Flags());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/jar/JarMarkerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/jar/JarMarkerTest.java b/src/test/java/org/apache/commons/compress/archivers/jar/JarMarkerTest.java
new file mode 100644
index 0000000..507a814
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/jar/JarMarkerTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress.archivers.jar;
+
+import static org.junit.Assert.fail;
+
+import java.util.zip.ZipException;
+import org.apache.commons.compress.archivers.zip.JarMarker;
+import org.junit.Test;
+
+public class JarMarkerTest {
+
+    @Test public void testJarMarkerLengthCheck() {
+        JarMarker jarMarker = JarMarker.getInstance();
+        try {
+            jarMarker.parseFromLocalFileData(null,0,1);
+            fail("should have thrown exception due to length of 1");
+        } catch (ZipException e) {
+
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/sevenz/CoverageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/CoverageTest.java
b/src/test/java/org/apache/commons/compress/archivers/sevenz/CoverageTest.java
new file mode 100644
index 0000000..c6801ae
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/CoverageTest.java
@@ -0,0 +1,24 @@
+package org.apache.commons.compress.archivers.sevenz;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class CoverageTest {
+
+    @Test public void testNidInstance() {
+        assertNotNull(new NID());
+    }
+
+    @Test public void testCLIInstance() {
+        CLI foo = new CLI();
+        assertNotNull(foo);
+        try {
+            CLI.main(new String[]{"/dev/null/not-there"});
+            fail("shouldn't be able to list contents of  a file that isn't there");
+        } catch (Exception ignored) {
+
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/zip/BinaryTreeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/BinaryTreeTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/BinaryTreeTest.java
index 930df01..fc0e94a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/BinaryTreeTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/BinaryTreeTest.java
@@ -47,4 +47,28 @@ public class BinaryTreeTest {
         assertEquals(6, tree.read(stream));
         assertEquals(7, tree.read(stream));
     }
+    @Test
+    public void testExceptions()  {
+         BinaryTree binaryFinary = new BinaryTree(4);
+         binaryFinary.addLeaf(0,0,0,1);
+        try {
+            binaryFinary.addLeaf(0,0,0,1);
+            fail("should have thrown illegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+
+        InputStream is = new ByteArrayInputStream(new byte[]{});
+        try {
+            BinaryTree.decode(is,0);
+            fail("should have thrown IOException");
+        } catch (IOException e) {
+
+        }
+        binaryFinary = new BinaryTree(4);
+        try {
+            binaryFinary.read(new BitStream(new ByteArrayInputStream(new byte[] {0})));
+            fail("expected read fail");
+        } catch (IOException e) {
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
index 5716fd7..13bdb53 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
@@ -20,6 +20,8 @@
 package org.apache.commons.compress.archivers.zip;
 
 import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -99,4 +101,20 @@ public class ExplodeSupportTest {
         testZipStreamWithImplodeCompression("target/test-classes/moby-imploded.zip", "README");
     }
 
+    @Test
+    public void testConstructorThrowsExceptions() {
+        try {
+            ExplodingInputStream eis = new  ExplodingInputStream(4095,2,new ByteArrayInputStream(new
byte[] {}));
+            fail("should have failed with illegal argument exception");
+        } catch (IllegalArgumentException e) {
+        }
+
+        try {
+            ExplodingInputStream eis = new  ExplodingInputStream(4096,4,new ByteArrayInputStream(new
byte[] {}));
+            fail("should have failed with illegal argument exception");
+        } catch (IllegalArgumentException e) {
+        }
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
index afa122e..3803817 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
@@ -93,6 +93,18 @@ public class ExtraFieldUtilsTest implements UnixStat {
                          e.getMessage());
         }
     }
+    @Test
+    public void testParseCentral() throws Exception {
+        final ZipExtraField[] ze = ExtraFieldUtils.parse(data,false);
+        assertEquals("number of fields", 2, ze.length);
+        assertTrue("type field 1", ze[0] instanceof AsiExtraField);
+        assertEquals("mode field 1", 040755,
+                     ((AsiExtraField) ze[0]).getMode());
+        assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
+        assertEquals("data length field 2", 1,
+                     ze[1].getCentralDirectoryLength().getValue());
+
+    }
 
     @Test
     public void testParseWithRead() throws Exception {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/zip/PkWareExtraHeaderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/PkWareExtraHeaderTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/PkWareExtraHeaderTest.java
new file mode 100644
index 0000000..315a189
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/PkWareExtraHeaderTest.java
@@ -0,0 +1,28 @@
+package org.apache.commons.compress.archivers.zip;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.commons.compress.archivers.zip.PKWareExtraHeader.EncryptionAlgorithm;
+import org.apache.commons.compress.archivers.zip.PKWareExtraHeader.HashAlgorithm;
+import org.junit.Test;
+
+public class PkWareExtraHeaderTest {
+
+    @Test public void testEncryptionAlgorithm() {
+        String name = "AES256";
+        int code = EncryptionAlgorithm.AES256.getCode();
+        EncryptionAlgorithm e = EncryptionAlgorithm.valueOf(name);
+        assertEquals(code,e.getCode());
+        assertNotNull(e);
+    }
+
+    @Test public void testHashAlgorithm() {
+        String name = "SHA256";
+        int code = HashAlgorithm.SHA256.getCode();
+        HashAlgorithm e = HashAlgorithm.valueOf(name);
+        assertEquals(code,e.getCode());
+        assertNotNull(e);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/zip/StreamCompressorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/StreamCompressorTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/StreamCompressorTest.java
index 27505c4..38ed531 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/StreamCompressorTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/StreamCompressorTest.java
@@ -17,14 +17,18 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
-import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.zip.Deflater;
 import java.util.zip.ZipEntry;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
 
 public class StreamCompressorTest {
 
@@ -55,4 +59,13 @@ public class StreamCompressorTest {
         // Note that this test really asserts stuff about the java Deflater, which might
be a little bit brittle
         assertArrayEquals(expected, actuals);
     }
-}
\ No newline at end of file
+
+    @Test
+    public void testCreateDataOutputCompressor() throws IOException {
+        DataOutput dataOutputStream = new DataOutputStream(new ByteArrayOutputStream());
+        try (StreamCompressor streamCompressor = StreamCompressor
+            .create(dataOutputStream, new Deflater(9))) {
+            assertNotNull(streamCompressor);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ffa1c55e/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
new file mode 100644
index 0000000..3387b63
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
@@ -0,0 +1,41 @@
+package org.apache.commons.compress.archivers.zip;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.hamcrest.core.IsInstanceOf;
+import org.junit.Test;
+
+public class ZipClassCoverageTest {
+
+    @Test
+    public void testConstructZip64RequiredException() {
+        Zip64RequiredException e = new Zip64RequiredException("critique of pure");
+        assertNotNull(e);
+    }
+    @Test
+    public void testMessageException() {
+        ZipArchiveEntry ze = new ZipArchiveEntry("hello");
+        String entryTooBigMessage = Zip64RequiredException.getEntryTooBigMessage(ze);
+        assertEquals("hello's size exceeds the limit of 4GByte.",
+            entryTooBigMessage);
+    }
+
+    @Test
+    public void testConstantConstructor()
+        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
InstantiationException {
+        Class<ZipConstants> clazz = ZipConstants.class;
+        Constructor<ZipConstants> constructor = clazz.getDeclaredConstructor();
+        assertFalse(constructor.isAccessible());
+        constructor.setAccessible(true);
+        Object o = constructor.newInstance();
+        assertThat(o, IsInstanceOf.instanceOf(clazz));
+        constructor.setAccessible(false);
+
+    }
+
+}


Mime
View raw message