commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/7] commons-compress git commit: Add-additional-Unit-Tests Added Unit Tests to increase coverage.
Date Thu, 06 Jul 2017 07:07:30 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master 8e95a81a4 -> 64573bb2e


Add-additional-Unit-Tests Added Unit Tests to increase coverage.


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

Branch: refs/heads/master
Commit: b09b95124bc27f39e27ecfed90ce40947bcbf663
Parents: 8e95a81
Author: Michael Hausegger <hausegger.michael@googlemail.comY>
Authored: Mon Jun 26 19:00:22 2017 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu Jul 6 09:04:09 2017 +0200

----------------------------------------------------------------------
 .../sevenz/AES256SHA256DecoderTest.java         | 90 ++++++++++++++++++++
 .../compress/archivers/sevenz/FolderTest.java   | 88 +++++++++++++++++++
 2 files changed, 178 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b09b9512/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
b/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
new file mode 100644
index 0000000..0671499
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256DecoderTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.sevenz;
+
+import org.junit.Test;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Unit tests for class {@link AES256SHA256Decoder}.
+ *
+ * @date 26.06.2017
+ * @see AES256SHA256Decoder
+ **/
+public class AES256SHA256DecoderTest {
+
+
+    @Test
+    public void testDecodeWithEmptyString() throws IOException {
+
+        AES256SHA256Decoder aES256SHA256Decoder = new AES256SHA256Decoder();
+        BufferedInputStream bufferedInputStream = new BufferedInputStream(null, 1801);
+        Coder coder = new Coder();
+        byte[] byteArray = new byte[2];
+        coder.properties = byteArray;
+        InputStream inputStream = aES256SHA256Decoder.decode("", bufferedInputStream, 1801,
coder, byteArray);
+
+        assertArrayEquals(new byte[] {(byte)0, (byte)0}, byteArray);
+        assertNotNull(inputStream);
+
+        ObjectInputStream objectInputStream = null;
+
+        try {
+            objectInputStream = new ObjectInputStream(inputStream);
+            fail("Expecting exception: IOException");
+        } catch(Throwable e) {
+            assertEquals("Decryption error (do you have the JCE Unlimited Strength Jurisdiction
Policy Files installed?)",e.getMessage());
+            assertEquals("org.apache.commons.compress.archivers.sevenz.AES256SHA256Decoder$1",
e.getStackTrace()[0].getClassName());
+        }
+
+    }
+
+
+    @Test
+    public void testDecodeWithNonEmptyString() throws IOException {
+
+        AES256SHA256Decoder aES256SHA256Decoder = new AES256SHA256Decoder();
+        BufferedInputStream bufferedInputStream = new BufferedInputStream(null, 3138);
+        Coder coder = new Coder();
+        byte[] byteArray = new byte[8];
+        byteArray[1] = (byte) (-72);
+        coder.properties = byteArray;
+        InputStream inputStream = aES256SHA256Decoder.decode("x", bufferedInputStream, 3138,
coder, coder.properties);
+
+        ObjectInputStream objectInputStream = null;
+
+        try {
+            objectInputStream = new ObjectInputStream(inputStream);
+            fail("Expecting exception: IOException");
+        } catch(Throwable e) {
+            assertEquals("Salt size + IV size too long in x",e.getMessage());
+            assertEquals("org.apache.commons.compress.archivers.sevenz.AES256SHA256Decoder$1",
e.getStackTrace()[0].getClassName());
+        }
+
+    }
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b09b9512/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java
new file mode 100644
index 0000000..1150b89
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.sevenz;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Unit tests for class {@link Folder}.
+ *
+ * @date 26.06.2017
+ * @see Folder
+ **/
+public class FolderTest {
+
+
+    @Test
+    public void testGetUnpackSizeForCoderOne() {
+
+        Folder folder = new Folder();
+        Coder[] coderArray = new Coder[5];
+        Coder coder = new Coder();
+        folder.coders = coderArray;
+
+        assertEquals(0L, folder.getUnpackSizeForCoder(coder));
+
+    }
+
+
+    @Test
+    public void testGetUnpackSizeOne() {
+
+        Folder folder = new Folder();
+        folder.totalOutputStreams = 266L;
+        BindPair[] bindPairArray = new BindPair[1];
+        BindPair bindPair = new BindPair();
+        bindPairArray[0] = bindPair;
+        folder.bindPairs = bindPairArray;
+        folder.totalOutputStreams = 1L;
+
+        assertEquals(0L, folder.getUnpackSize());
+
+    }
+
+
+    @Test
+    public void testGetUnpackSizeTwo() {
+
+        Folder folder = new Folder();
+
+        assertEquals(0L, folder.getUnpackSize());
+
+    }
+
+
+    @Test
+    public void testFindBindPairForInStream() {
+
+        Folder folder = new Folder();
+        BindPair[] bindPairArray = new BindPair[1];
+        BindPair bindPair = new BindPair();
+        bindPairArray[0] = bindPair;
+        folder.bindPairs = bindPairArray;
+
+        assertEquals(0, folder.findBindPairForInStream(0));
+
+    }
+
+
+}
\ No newline at end of file


Mime
View raw message