commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1611914 - in /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate: ./ DeflateCompressorInputStreamTest.java DeflateCompressorOutputStreamTest.java DeflateParametersTest.java
Date Sat, 19 Jul 2014 13:29:35 GMT
Author: bodewig
Date: Sat Jul 19 13:29:35 2014
New Revision: 1611914

URL: http://svn.apache.org/r1611914
Log:
COMPRESS-263 some more tests to increas coverage

Added:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
  (with props)
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java
  (with props)
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.java
  (with props)

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java?rev=1611914&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
(added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
Sat Jul 19 13:29:35 2014
@@ -0,0 +1,92 @@
+/*
+ * 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.compressors.deflate;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.utils.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DeflateCompressorInputStreamTest {
+
+    @Test
+    public void availableShouldReturnNonZero() throws IOException {
+        final File input = AbstractTestCase.getFile("bla.tar.deflatez");
+        final InputStream is = new FileInputStream(input);
+        try {
+            DeflateCompressorInputStream in =
+                new DeflateCompressorInputStream(is);
+            Assert.assertTrue(in.available() > 0);
+            in.close();
+        } finally {
+            is.close();
+        }
+    }
+
+    @Test
+    public void shouldBeAbleToSkipAByte() throws IOException {
+        final File input = AbstractTestCase.getFile("bla.tar.deflatez");
+        final InputStream is = new FileInputStream(input);
+        try {
+            DeflateCompressorInputStream in =
+                new DeflateCompressorInputStream(is);
+            Assert.assertEquals(1, in.skip(1));
+            in.close();
+        } finally {
+            is.close();
+        }
+    }
+
+    @Test
+    public void singleByteReadWorksAsExpected() throws IOException {
+        final File input = AbstractTestCase.getFile("bla.tar.deflatez");
+        final InputStream is = new FileInputStream(input);
+        try {
+            DeflateCompressorInputStream in =
+                new DeflateCompressorInputStream(is);
+            // tar header starts with filename "test1.xml"
+            Assert.assertEquals('t', in.read());
+            in.close();
+        } finally {
+            is.close();
+        }
+    }
+
+    @Test
+    public void singleByteReadReturnsMinusOneAtEof() throws IOException {
+        final File input = AbstractTestCase.getFile("bla.tar.deflatez");
+        final InputStream is = new FileInputStream(input);
+        try {
+            DeflateCompressorInputStream in =
+                new DeflateCompressorInputStream(is);
+            // tar header starts with filename "test1.xml"
+            IOUtils.toByteArray(in);
+            Assert.assertEquals(-1, in.read());
+            in.close();
+        } finally {
+            is.close();
+        }
+    }
+
+}

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java?rev=1611914&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java
(added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java
Sat Jul 19 13:29:35 2014
@@ -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.compressors.deflate;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class DeflateCompressorOutputStreamTest {
+
+    @Test
+    public void canReadASingleByteFlushAndFinish() throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        DeflateCompressorOutputStream cos = new DeflateCompressorOutputStream(bos);
+        cos.write(99);
+        cos.flush();
+        cos.finish();
+        Assert.assertTrue(bos.toByteArray().length > 0);
+    }
+
+}

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.java?rev=1611914&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.java
(added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.java
Sat Jul 19 13:29:35 2014
@@ -0,0 +1,44 @@
+/*
+ * 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.compressors.deflate;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DeflateParametersTest {
+
+    @Test
+    public void shouldBeAbleToSetCompressionLevel() {
+        DeflateParameters p = new DeflateParameters();
+        p.setCompressionLevel(5);
+        Assert.assertEquals(5, p.getCompressionLevel());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldNotBeAbleToSetCompressionLevelToANegativeValue() {
+        DeflateParameters p = new DeflateParameters();
+        p.setCompressionLevel(-2);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldNotBeAbleToSetCompressionLevelToADoubleDigitValue() {
+        DeflateParameters p = new DeflateParameters();
+        p.setCompressionLevel(12);
+    }
+}

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message