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 2cf9118b Add missing test CopyUtils#copy_stringToOutputStreamString() 2cf9118b is described below commit 2cf9118b96761bc5f2105f7e9ff2c9a319afc505 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Mon Jul 25 10:40:11 2022 -0400 Add missing test CopyUtils#copy_stringToOutputStreamString() --- .../java/org/apache/commons/io/CopyUtilsTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/apache/commons/io/CopyUtilsTest.java b/src/test/java/org/apache/commons/io/CopyUtilsTest.java index 7f6fc667..c3a0fe72 100644 --- a/src/test/java/org/apache/commons/io/CopyUtilsTest.java +++ b/src/test/java/org/apache/commons/io/CopyUtilsTest.java @@ -142,6 +142,25 @@ public class CopyUtilsTest { assertArrayEquals(inData, baout.toByteArray(), "Content differs"); } + @Test + public void copy_stringToOutputStreamString() throws Exception { + final String str = new String(inData, StandardCharsets.US_ASCII); + + final ByteArrayOutputStream baout = new ByteArrayOutputStream(); + final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true); + + CopyUtils.copy(str, out, StandardCharsets.US_ASCII.name()); + //Note: this method *does* flush. It is equivalent to: + // OutputStreamWriter _out = new OutputStreamWriter(fout); + // IOUtils.copy( str, _out, 4096 ); // copy( Reader, Writer, int ); + // _out.flush(); + // out = fout; + // note: we don't flush here; this IOUtils method does it for us + + assertEquals(inData.length, baout.size(), "Sizes differ"); + assertArrayEquals(inData, baout.toByteArray(), "Content differs"); + } + @Test public void copy_stringToWriter() throws Exception { final String str = new String(inData, StandardCharsets.US_ASCII);