You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by kr...@apache.org on 2015/06/25 21:08:16 UTC

svn commit: r1687613 - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/output/ChunkedWriter.java test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java test/java/org/apache/commons/io/output/ChunkedWriterTest.java

Author: krosenvold
Date: Thu Jun 25 19:08:15 2015
New Revision: 1687613

URL: http://svn.apache.org/r1687613
Log:
Added a couple of tests to increase coverage somewhat

Added:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java
Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java?rev=1687613&r1=1687612&r2=1687613&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java Thu Jun 25 19:08:15 2015
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.io.Writer;
 
 /**
- * OutputStream which breaks larger output blocks into chunks.
+ * Writer which breaks larger output blocks into chunks.
  * Native code may need to copy the input array; if the write buffer
  * is very large this can cause OOME.
  *

Added: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java?rev=1687613&view=auto
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java (added)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java Thu Jun 25 19:08:15 2015
@@ -0,0 +1,49 @@
+/*
+ * 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.io.output;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.Test;
+
+/**
+ * Test the chunked output stream
+ */
+public class ChunkedOutputStreamTest {
+
+    @Test
+    public void write_four_chunks() throws Exception {
+        final AtomicInteger numWrites = new AtomicInteger();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream() {
+            @Override
+            public void write(byte[] b, int off, int len) {
+                numWrites.incrementAndGet();
+                super.write(b, off, len);
+            }
+        };
+        ChunkedOutputStream chunked = new ChunkedOutputStream(baos, 10);
+        chunked.write("0123456789012345678901234567891".getBytes());
+        assertEquals(4, numWrites.get());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void negative_chunksize_not_permitted() {
+        new ChunkedOutputStream(new ByteArrayOutputStream(), 0);
+    }
+}

Added: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java?rev=1687613&view=auto
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java (added)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java Thu Jun 25 19:08:15 2015
@@ -0,0 +1,50 @@
+/*
+ * 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.io.output;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.Test;
+
+public class ChunkedWriterTest {
+    @Test
+    public void write_four_chunks() throws Exception {
+        final AtomicInteger numWrites = new AtomicInteger();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OutputStreamWriter osw = new OutputStreamWriter(baos) {
+            @Override
+            public void write(char[] cbuf, int off, int len) throws IOException {
+                numWrites.incrementAndGet();
+                super.write(cbuf, off, len);
+            }
+        };
+
+        ChunkedWriter chunked = new ChunkedWriter(osw, 10);
+        chunked.write("0123456789012345678901234567891".toCharArray());
+        chunked.flush();
+        assertEquals(4, numWrites.get());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void negative_chunksize_not_permitted() {
+        new ChunkedWriter(new OutputStreamWriter(new ByteArrayOutputStream()), 0);
+    }
+}