Skip to content

Commit 52c8bd0

Browse files
committed
Add a test
1 parent 1eaf0e4 commit 52c8bd0

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
*/
1717
package org.apache.commons.io.output;
1818

19+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertThrows;
2122

2223
import java.io.IOException;
24+
import java.nio.file.Files;
25+
import java.nio.file.Path;
2326
import java.util.concurrent.atomic.AtomicInteger;
2427

2528
import org.apache.commons.io.IOUtils;
29+
import org.apache.commons.io.file.TempFile;
30+
import org.apache.commons.lang3.ArrayFill;
2631
import org.junit.jupiter.api.Test;
2732

2833
/**
@@ -40,8 +45,13 @@ public void write(final byte[] b, final int off, final int len) {
4045
};
4146
}
4247

48+
/**
49+
* Tests the default chunk size with a ByteArrayOutputStream.
50+
*
51+
* @throws IOException
52+
*/
4353
@Test
44-
public void testDefaultBuilder() throws IOException {
54+
public void testBuildSetByteArrayOutputStream() throws IOException {
4555
final AtomicInteger numWrites = new AtomicInteger();
4656
try (ByteArrayOutputStream baos = newByteArrayOutputStream(numWrites);
4757
final ChunkedOutputStream chunked = ChunkedOutputStream.builder().setOutputStream(baos).get()) {
@@ -51,6 +61,23 @@ public void testDefaultBuilder() throws IOException {
5161
assertThrows(IllegalStateException.class, () -> ChunkedOutputStream.builder().get());
5262
}
5363

64+
/**
65+
* Tests the default chunk size with a Path.
66+
*
67+
* @throws IOException
68+
*/
69+
@Test
70+
public void testBuildSetPath() throws IOException {
71+
try (TempFile tempFile = TempFile.create("test-", ".txt")) {
72+
final byte[] fill = ArrayFill.fill(new byte[IOUtils.DEFAULT_BUFFER_SIZE + 1], (byte) 'a');
73+
final Path tempPath = tempFile.get();
74+
try (ChunkedOutputStream chunked = ChunkedOutputStream.builder().setPath(tempPath).get()) {
75+
chunked.write(fill);
76+
}
77+
assertArrayEquals(fill, Files.readAllBytes(tempPath));
78+
}
79+
}
80+
5481
@Test
5582
public void testDefaultConstructor() throws IOException {
5683
final AtomicInteger numWrites = new AtomicInteger();

0 commit comments

Comments
 (0)