[7/7] commons-compress git commit: closes #33, thanks @TheRealHaui
closes #33, thanks @TheRealHaui Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0960a387 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0960a387 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0960a387 Branch: refs/heads/master Commit: 0960a387c00bf0409412bc283b3ee7fab963f718 Parents: 3c2419d Author: Stefan BodewigAuthored: Sat Jun 17 10:21:17 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:21:17 2017 +0200 -- --
[6/7] commons-compress git commit: add-some-Unit-Tests Minor variable renaming.
add-some-Unit-Tests Minor variable renaming. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/496691bf Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/496691bf Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/496691bf Branch: refs/heads/master Commit: 496691bfd82374f1c1bfee8719309343c2fa878d Parents: 6fe9ae8 Author: Michael HauseggerAuthored: Fri Jun 16 20:38:00 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:20:10 2017 +0200 -- .../utils/ChecksumCalculatingInputStreamTest.java | 16 .../utils/ChecksumVerifyingInputStreamTest.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/496691bf/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java index 089c685..b97b09e 100644 --- a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java @@ -38,10 +38,10 @@ public class ChecksumCalculatingInputStreamTest { @Test public void testSkipReturningZero() throws IOException { -Adler32 adler32_ = new Adler32(); +Adler32 adler32 = new Adler32(); byte[] byteArray = new byte[0]; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); -ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32_, byteArrayInputStream); +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32, byteArrayInputStream); long skipResult = checksumCalculatingInputStream.skip(60L); assertEquals(0L, skipResult); @@ -55,10 +55,10 @@ public class ChecksumCalculatingInputStreamTest { @Test public void testSkipReturningPositive() throws IOException { -Adler32 adler32_ = new Adler32(); +Adler32 adler32 = new Adler32(); byte[] byteArray = new byte[6]; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); -ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32_, byteArrayInputStream); +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32, byteArrayInputStream); long skipResult = checksumCalculatingInputStream.skip((byte)0); assertEquals(1L, skipResult); @@ -71,10 +71,10 @@ public class ChecksumCalculatingInputStreamTest { @Test public void testReadTakingNoArguments() throws IOException { -Adler32 adler32_ = new Adler32(); +Adler32 adler32 = new Adler32(); byte[] byteArray = new byte[6]; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); -ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32_, byteArrayInputStream); +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32, byteArrayInputStream); BufferedInputStream bufferedInputStream = new BufferedInputStream(checksumCalculatingInputStream); int inputStreamReadResult = bufferedInputStream.read(byteArray, 0, 1); int checkSumCalculationReadResult = checksumCalculatingInputStream.read(); @@ -92,10 +92,10 @@ public class ChecksumCalculatingInputStreamTest { @Test public void testReadTakingByteArray() throws IOException { -Adler32 adler32_ = new Adler32(); +Adler32 adler32 = new Adler32(); byte[] byteArray = new byte[6]; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); -ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32_, byteArrayInputStream); +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(adler32, byteArrayInputStream); int readResult = checksumCalculatingInputStream.read(byteArray); assertEquals(6, readResult); http://git-wip-us.apache.org/repos/asf/commons-compress/blob/496691bf/src/test/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStreamTest.java
[1/7] commons-compress git commit: add-some-Unit-Tests Added additional Unit Tests.
Repository: commons-compress Updated Branches: refs/heads/master 7254daa3f -> 0960a387c add-some-Unit-Tests Added additional Unit Tests. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/3c2419db Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/3c2419db Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/3c2419db Branch: refs/heads/master Commit: 3c2419db66d156dae631715d5d42ef90e36ad7da Parents: cf9f45b Author: Michael HauseggerAuthored: Fri Jun 16 22:16:06 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:20:10 2017 +0200 -- .../compress/archivers/cpio/CpioUtilTest.java | 31 +- .../commons/compress/changes/ChangeTest.java| 64 .../xz/XZCompressorOutputStreamTest.java| 51 .../z/ZCompressorInputStreamTest.java | 54 + 4 files changed, 198 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/3c2419db/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java -- diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java index 329d481..5b1edb5 100644 --- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java @@ -18,11 +18,11 @@ */ package org.apache.commons.compress.archivers.cpio; +import org.junit.Test; + import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import org.junit.Test; - public class CpioUtilTest { @Test @@ -53,4 +53,31 @@ public class CpioUtilTest { true)); } + +@Test(expected = UnsupportedOperationException.class) +public void testLong2byteArrayWithZeroThrowsUnsupportedOperationException() { + +CpioUtil.long2byteArray(0L, 0, false); + +} + + +@Test(expected = UnsupportedOperationException.class) +public void testLong2byteArrayWithPositiveThrowsUnsupportedOperationException() { + +CpioUtil.long2byteArray(0L, 1021, false); + +} + + +@Test(expected = UnsupportedOperationException.class) +public void testByteArray2longThrowsUnsupportedOperationException() { + +byte[] byteArray = new byte[1]; + +CpioUtil.byteArray2long(byteArray, true); + +} + + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-compress/blob/3c2419db/src/test/java/org/apache/commons/compress/changes/ChangeTest.java -- diff --git a/src/test/java/org/apache/commons/compress/changes/ChangeTest.java b/src/test/java/org/apache/commons/compress/changes/ChangeTest.java new file mode 100644 index 000..907041c --- /dev/null +++ b/src/test/java/org/apache/commons/compress/changes/ChangeTest.java @@ -0,0 +1,64 @@ +/* + * 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.changes; + +import org.apache.commons.compress.archivers.memory.MemoryArchiveEntry; +import org.junit.Test; + +import java.io.PipedInputStream; + + +/** + * Unit tests for class {@link Change}. + * + * @date 16.06.2017 + * @see Change + **/ +public class ChangeTest { + + +@Test(expected = NullPointerException.class) +public void testFailsToCreateChangeTakingFourArgumentsThrowsNullPointerExceptionOne() { + +MemoryArchiveEntry memoryArchiveEntry = new MemoryArchiveEntry("x"); + +Change change = new Change(memoryArchiveEntry, null, false); + +} + + +@Test(expected = NullPointerException.class) +public void testFailsToCreateChangeTakingFourArgumentsThrowsNullPointerExceptionTwo() { + +PipedInputStream pipedInputStream = new
[2/7] commons-compress git commit: add-some-Unit-Tests Added myself as contributor to pom.xml as "requested" by Stefan Bodewig.
add-some-Unit-Tests Added myself as contributor to pom.xml as "requested" by Stefan Bodewig. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/cf9f45bc Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/cf9f45bc Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/cf9f45bc Branch: refs/heads/master Commit: cf9f45bc545fced1647fa8aed01f504dfa35718f Parents: 496691b Author: Michael HauseggerAuthored: Fri Jun 16 20:44:40 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:20:10 2017 +0200 -- pom.xml | 4 1 file changed, 4 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/cf9f45bc/pom.xml -- diff --git a/pom.xml b/pom.xml index 63d092e..fdf1721 100644 --- a/pom.xml +++ b/pom.xml @@ -169,6 +169,10 @@ jar, tar, zip, dump, 7z, arj. BELUGA BEHR + + Michael Hausegger + hausegger.mich...@googlemail.com +
[3/7] commons-compress git commit: add-some-Unit-Tests Removed @author tags in comments.
add-some-Unit-Tests Removed @author tags in comments. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b5848b2f Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b5848b2f Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b5848b2f Branch: refs/heads/master Commit: b5848b2f1f8b49502dbe5255128a70ca5c3abb06 Parents: b861b4f Author: Michael HauseggerAuthored: Fri Jun 16 20:12:20 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:20:10 2017 +0200 -- .../commons/compress/utils/ChecksumCalculatingInputStreamTest.java | 1 - .../commons/compress/utils/ChecksumVerifyingInputStreamTest.java| 1 - .../apache/commons/compress/utils/ServiceLoaderIteratorTest.java| 1 - 3 files changed, 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b5848b2f/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java index 09133d3..ee47798 100644 --- a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java @@ -28,7 +28,6 @@ import static org.junit.Assert.*; /** * Unit tests for class {@link ChecksumCalculatingInputStream org.apache.commons.compress.utils.ChecksumCalculatingInputStream}. * - * @author Michael Hausegger, hausegger.mich...@googlemail.com * @date 13.06.2017 * @see ChecksumCalculatingInputStream **/ http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b5848b2f/src/test/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStreamTest.java index e63d6aa..63a1d11 100644 --- a/src/test/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStreamTest.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertEquals; /** * Unit tests for class {@link ChecksumVerifyingInputStream org.apache.commons.compress.utils.ChecksumVerifyingInputStream}. * - * @author Michael Hausegger, hausegger.mich...@googlemail.com * @date 13.06.2017 * @see ChecksumVerifyingInputStream **/ http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b5848b2f/src/test/java/org/apache/commons/compress/utils/ServiceLoaderIteratorTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ServiceLoaderIteratorTest.java b/src/test/java/org/apache/commons/compress/utils/ServiceLoaderIteratorTest.java index 0aa1248..c39f401 100644 --- a/src/test/java/org/apache/commons/compress/utils/ServiceLoaderIteratorTest.java +++ b/src/test/java/org/apache/commons/compress/utils/ServiceLoaderIteratorTest.java @@ -27,7 +27,6 @@ import static org.junit.Assert.assertFalse; /** * Unit tests for class {@link ServiceLoaderIterator org.apache.commons.compress.utils.ServiceLoaderIterator}. * - * @author Michael Hausegger, hausegger.mich...@googlemail.com * @date 13.06.2017 * @see ServiceLoaderIterator **/
[4/7] commons-compress git commit: add-some-Unit-Tests Added some Unit Tests to increase code coverage.
add-some-Unit-Tests Added some Unit Tests to increase code 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/b861b4f0 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b861b4f0 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b861b4f0 Branch: refs/heads/master Commit: b861b4f0e45135e737e1ec2a514d3051157c3c7b Parents: 7254daa Author: Michael HauseggerAuthored: Tue Jun 13 23:47:50 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:20:10 2017 +0200 -- .../commons/compress/ArchiveUtilsTest.java | 52 +++- .../ChecksumCalculatingInputStreamTest.java | 122 +++ .../utils/ChecksumVerifyingInputStreamTest.java | 87 + .../utils/ServiceLoaderIteratorTest.java| 74 +++ 4 files changed, 333 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b861b4f0/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java -- diff --git a/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java b/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java index 5dc7925..54a2451 100644 --- a/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java +++ b/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java @@ -18,11 +18,12 @@ package org.apache.commons.compress; -import static org.junit.Assert.*; - +import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry; import org.apache.commons.compress.utils.ArchiveUtils; import org.junit.Test; +import static org.junit.Assert.*; + public class ArchiveUtilsTest extends AbstractTestCase { private static final int bytesToTest = 50; @@ -95,6 +96,53 @@ public class ArchiveUtilsTest extends AbstractTestCase { assertEquals(expected, ArchiveUtils.sanitize(input)); } +@Test +public void testIsEqualWithNullWithPositive() { + +byte[] byteArray = new byte[8]; +byteArray[1] = (byte) (-77); + +assertFalse(ArchiveUtils.isEqualWithNull(byteArray, 0, (byte)0, byteArray, (byte)0, (byte)80)); + +} + +@Test +public void testToAsciiBytes() { + +byte[] byteArray = ArchiveUtils.toAsciiBytes("SOCKET"); + +assertArrayEquals(new byte[] {(byte)83, (byte)79, (byte)67, (byte)75, (byte)69, (byte)84}, byteArray); + +assertFalse(ArchiveUtils.isEqualWithNull(byteArray, 0, 46, byteArray, 63, 0)); + +} + +@Test +public void testToStringWithNonNull() { + +SevenZArchiveEntry sevenZArchiveEntry = new SevenZArchiveEntry(); +String string = ArchiveUtils.toString(sevenZArchiveEntry); + +assertEquals("- 0 null", string); + +} + +@Test +public void testIsEqual() { + +assertTrue(ArchiveUtils.isEqual((byte[]) null, 0, 0, (byte[]) null, 0, 0)); + +} + +@Test(expected = StringIndexOutOfBoundsException.class) +public void testToAsciiStringThrowsStringIndexOutOfBoundsException() { + +byte[] byteArray = new byte[3]; + +ArchiveUtils.toAsciiString(byteArray, 940, 2730); + +} + private void asciiToByteAndBackOK(final String inputString) { assertEquals(inputString, ArchiveUtils.toAsciiString(ArchiveUtils.toAsciiBytes(inputString))); } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b861b4f0/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java new file mode 100644 index 000..09133d3 --- /dev/null +++ b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java @@ -0,0 +1,122 @@ +/* + * 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
[5/7] commons-compress git commit: add-some-Unit-Tests Removed test testGetValueThrowsNullPointerException in class ChecksumCalculatingInputStreamTest. Test represented a bug/defect which is going to
add-some-Unit-Tests Removed test testGetValueThrowsNullPointerException in class ChecksumCalculatingInputStreamTest. Test represented a bug/defect which is going to be fixed in a different branch. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/6fe9ae88 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/6fe9ae88 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/6fe9ae88 Branch: refs/heads/master Commit: 6fe9ae88052b89dbf67468776a725b0dac57422a Parents: b5848b2 Author: Michael HauseggerAuthored: Fri Jun 16 20:22:10 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 10:20:10 2017 +0200 -- .../utils/ChecksumCalculatingInputStreamTest.java| 11 --- 1 file changed, 11 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6fe9ae88/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java index ee47798..089c685 100644 --- a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java @@ -89,17 +89,6 @@ public class ChecksumCalculatingInputStreamTest { } -@Test(expected = NullPointerException.class) //I assume this behaviour to be a bug or at least a defect. -public void testGetValueThrowsNullPointerException() { - -ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(null,null); - -checksumCalculatingInputStream.getValue(); - - -} - - @Test public void testReadTakingByteArray() throws IOException {
commons-compress git commit: reformulate test
Repository: commons-compress Updated Branches: refs/heads/master 0960a387c -> b53ead4b4 reformulate test Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b53ead4b Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b53ead4b Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b53ead4b Branch: refs/heads/master Commit: b53ead4b43c6c248b1a39f4a1cce7a0c4062285d Parents: 0960a38 Author: Stefan BodewigAuthored: Sat Jun 17 19:59:34 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 19:59:34 2017 +0200 -- .../xz/XZCompressorOutputStreamTest.java | 18 +++--- 1 file changed, 11 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b53ead4b/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java index aea5942..49e66f8 100644 --- a/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java @@ -20,6 +20,7 @@ package org.apache.commons.compress.compressors.xz; import org.junit.Test; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -39,13 +40,16 @@ public class XZCompressorOutputStreamTest { public void testWrite() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(4590); -XZCompressorOutputStream xZCompressorOutputStream = new XZCompressorOutputStream(byteArrayOutputStream); -xZCompressorOutputStream.write(4590); - -assertEquals(24, byteArrayOutputStream.size()); - assertEquals("\uFFFD7zXZ\u\u\u0004\uFFFD\u05B4F\u0002\u!\u0001\u0016\u\u\ut/\uFFFD", byteArrayOutputStream.toString()); - +try (XZCompressorOutputStream xZCompressorOutputStream = new XZCompressorOutputStream(byteArrayOutputStream)) { +xZCompressorOutputStream.write(4590); +} + +try (XZCompressorInputStream xZCompressorInputStream = +new XZCompressorInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray( { +assertEquals(4590 % 256, xZCompressorInputStream.read()); +assertEquals(-1, xZCompressorInputStream.read()); +} } -} \ No newline at end of file +}
[1/2] commons-compress git commit: COMPRESS-412 NullPointerException defect in ChecksumCalculatingInputStream#getValue() fixed.
Repository: commons-compress Updated Branches: refs/heads/master b53ead4b4 -> 8c3201bbd COMPRESS-412 NullPointerException defect in ChecksumCalculatingInputStream#getValue() fixed. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/6f379134 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/6f379134 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/6f379134 Branch: refs/heads/master Commit: 6f379134ae1807cd404ed6c9579707e5dc6a6df0 Parents: b53ead4 Author: Michael HauseggerAuthored: Fri Jun 16 21:30:03 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 20:29:37 2017 +0200 -- .../utils/ChecksumCalculatingInputStream.java | 9 +++ .../ChecksumCalculatingInputStreamTest.java | 26 2 files changed, 35 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6f379134/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java -- diff --git a/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java b/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java index ebf44fd..4a408a5 100644 --- a/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java +++ b/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java @@ -31,6 +31,15 @@ public class ChecksumCalculatingInputStream extends InputStream { private final Checksum checksum; public ChecksumCalculatingInputStream(final Checksum checksum, final InputStream in) { + +if ( checksum == null ){ +throw new NullPointerException("Parameter checksum must not be null"); +} + +if ( in == null ){ +throw new NullPointerException("Parameter in must not be null"); +} + this.checksum = checksum; this.in = in; } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6f379134/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java -- diff --git a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java index b97b09e..a9e5246 100644 --- a/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStreamTest.java @@ -22,6 +22,7 @@ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.zip.Adler32; +import java.util.zip.CRC32; import static org.junit.Assert.*; @@ -106,5 +107,30 @@ public class ChecksumCalculatingInputStreamTest { } +@Test(expected = NullPointerException.class) +public void testClassInstantiationWithParameterBeingNullThrowsNullPointerExceptionOne() { + +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(null,null); + + +} + + +@Test(expected = NullPointerException.class) +public void testClassInstantiationWithParameterBeingNullThrowsNullPointerExceptionTwo() { + +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(null,new ByteArrayInputStream(new byte[1])); + + +} + + +@Test(expected = NullPointerException.class) +public void testClassInstantiationWithParameterBeingNullThrowsNullPointerExceptionThree() { + +ChecksumCalculatingInputStream checksumCalculatingInputStream = new ChecksumCalculatingInputStream(new CRC32(),null); + +} + } \ No newline at end of file
[2/2] commons-compress git commit: COMPRESS-412 record change.
COMPRESS-412 record change. closes #35 Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/8c3201bb Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/8c3201bb Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/8c3201bb Branch: refs/heads/master Commit: 8c3201bbd8f10d5162443aa617a7711219f55d46 Parents: 6f37913 Author: Stefan BodewigAuthored: Sat Jun 17 20:34:27 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 20:34:27 2017 +0200 -- src/changes/changes.xml | 5 + 1 file changed, 5 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8c3201bb/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 38831db..0ec4038 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -72,6 +72,11 @@ The type attribute can be add,update,fix,remove. can be used to ensure writing always happens in blocks of a given size. + +Made sure ChecksumCalculatingInputStream receives valid +checksum and input stream instances via the cnstructor. +
[4/5] commons-compress git commit: COMPRESS-411 actually use formatLongBinary
COMPRESS-411 actually use formatLongBinary Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/02735ad7 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/02735ad7 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/02735ad7 Branch: refs/heads/master Commit: 02735ad7e6313515a846bc15bcc89cf254f8161f Parents: 137aa57 Author: Stefan BodewigAuthored: Sat Jun 17 21:47:10 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 21:47:10 2017 +0200 -- .../java/org/apache/commons/compress/archivers/tar/TarUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/02735ad7/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java -- diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index 39ce5c1..d132d9d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -484,8 +484,9 @@ public class TarUtils { if (length < 9) { formatLongBinary(value, buf, offset, length, negative); +} else { +formatBigIntegerBinary(value, buf, offset, length, negative); } -formatBigIntegerBinary(value, buf, offset, length, negative); buf[offset] = (byte) (negative ? 0xff : 0x80); return offset + length;
[3/5] commons-compress git commit: add an extra sanity check
add an extra sanity check Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/137aa57f Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/137aa57f Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/137aa57f Branch: refs/heads/master Commit: 137aa57f9291b5f390de740266042587cfede7ce Parents: 2c8892a Author: Stefan BodewigAuthored: Sat Jun 17 21:46:53 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 21:46:53 2017 +0200 -- .../java/org/apache/commons/compress/archivers/tar/TarUtils.java | 4 1 file changed, 4 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/137aa57f/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java -- diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index 4e99a20..39ce5c1 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -519,6 +519,10 @@ public class TarUtils { final BigInteger val = BigInteger.valueOf(value); final byte[] b = val.toByteArray(); final int len = b.length; +if (len > length - 1) { +throw new IllegalArgumentException("Value " + value + +" is too large for " + length + " byte field."); +} final int off = offset + length - len; System.arraycopy(b, 0, buf, off, len); final byte fill = (byte) (negative ? 0xff : 0);
[1/5] commons-compress git commit: COMPRESS-411 ensure we really set the most sig byte when length is 8
Repository: commons-compress Updated Branches: refs/heads/master 8c3201bbd -> 4be9979b4 COMPRESS-411 ensure we really set the most sig byte when length is 8 Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/6b2bd2df Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/6b2bd2df Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/6b2bd2df Branch: refs/heads/master Commit: 6b2bd2df127be522a18d044980e84a8b638f25b7 Parents: 8c3201b Author: Stefan BodewigAuthored: Sat Jun 17 21:45:04 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 21:45:04 2017 +0200 -- .../java/org/apache/commons/compress/archivers/tar/TarUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6b2bd2df/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java -- diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index f95bbf3..c0dac4c 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -503,8 +503,8 @@ public class TarUtils { } if (negative) { val ^= max - 1; -val |= 0xff << bits; val++; +val |= 0xffl << bits; } for (int i = offset + length - 1; i >= offset; i--) { buf[i] = (byte) val;
[5/5] commons-compress git commit: COMPRESS-411 clearer formulation of the same test
COMPRESS-411 clearer formulation of the same test Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/4be9979b Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/4be9979b Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/4be9979b Branch: refs/heads/master Commit: 4be9979b45ceadc50dc24607884d34613fead1f5 Parents: 02735ad Author: Stefan BodewigAuthored: Sat Jun 17 21:47:43 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 21:47:43 2017 +0200 -- .../org/apache/commons/compress/archivers/tar/TarUtilsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/4be9979b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java -- diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java index a4ef25b..87f6b27 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java @@ -160,7 +160,8 @@ public class TarUtilsTest { checkRoundTripOctalOrBinary(1, length); checkRoundTripOctalOrBinary(TarConstants.MAXSIZE, length); // will need binary format checkRoundTripOctalOrBinary(-1, length); // will need binary format -checkRoundTripOctalOrBinary(0xff01l, length); +checkRoundTripOctalOrBinary(0xffl, length); +checkRoundTripOctalOrBinary(-0xffl, length); } // Check correct trailing bytes are generated
[2/5] commons-compress git commit: COMPRESS-411 Math.abs is dangerous
COMPRESS-411 Math.abs is dangerous Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/2c8892a2 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/2c8892a2 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/2c8892a2 Branch: refs/heads/master Commit: 2c8892a206c9374b0cde6fce72299b0fe630f3a0 Parents: 6b2bd2d Author: Stefan BodewigAuthored: Sat Jun 17 21:46:25 2017 +0200 Committer: Stefan Bodewig Committed: Sat Jun 17 21:46:25 2017 +0200 -- .../java/org/apache/commons/compress/archivers/tar/TarUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2c8892a2/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java -- diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index c0dac4c..4e99a20 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -496,8 +496,8 @@ public class TarUtils { final boolean negative) { final int bits = (length - 1) * 8; final long max = 1l << bits; -long val = Math.abs(value); -if (val >= max) { +long val = Math.abs(value); // Long.MIN_VALUE stays Long.MIN_VALUE +if (val < 0 || val >= max) { throw new IllegalArgumentException("Value " + value + " is too large for " + length + " byte field."); }