This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new b0955d61 Add missing test
CopyUtils#testCopy_readerToOutputStreamString()
b0955d61 is described below
commit b0955d612f289710beaeb15e8c0aff97bf8e2006
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jul 25 12:56:58 2022 -0400
Add missing test CopyUtils#testCopy_readerToOutputStreamString()
---
.../java/org/apache/commons/io/CopyUtilsTest.java | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/test/java/org/apache/commons/io/CopyUtilsTest.java
b/src/test/java/org/apache/commons/io/CopyUtilsTest.java
index c3a0fe72..ba9f2d18 100644
--- a/src/test/java/org/apache/commons/io/CopyUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/CopyUtilsTest.java
@@ -224,6 +224,28 @@ public class CopyUtilsTest {
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
}
+ @SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
+ public void testCopy_readerToOutputStreamString() throws Exception {
+ InputStream in = new ByteArrayInputStream(inData);
+ in = new ThrowOnCloseInputStream(in);
+ final Reader reader = new java.io.InputStreamReader(in,
StandardCharsets.US_ASCII);
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout,
false, true);
+
+ CopyUtils.copy(reader, out, StandardCharsets.US_ASCII.name());
+ //Note: this method *does* flush. It is equivalent to:
+ // OutputStreamWriter _out = new OutputStreamWriter(fout);
+ // IOUtils.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
+ // _out.flush();
+ // out = fout;
+
+ // Note: rely on the method to flush
+ assertEquals(inData.length, baout.size(), "Sizes differ");
+ assertArrayEquals(inData, baout.toByteArray(), "Content differs");
+ }
+
@Test
public void testCtor() {
new CopyUtils();