Skip to content

Commit 2cf9118

Browse files
author
Gary Gregory
committed
Add missing test CopyUtils#copy_stringToOutputStreamString()
1 parent 7db39c0 commit 2cf9118

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/test/java/org/apache/commons/io/CopyUtilsTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ public void copy_stringToOutputStream() throws Exception {
142142
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
143143
}
144144

145+
@Test
146+
public void copy_stringToOutputStreamString() throws Exception {
147+
final String str = new String(inData, StandardCharsets.US_ASCII);
148+
149+
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
150+
final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true);
151+
152+
CopyUtils.copy(str, out, StandardCharsets.US_ASCII.name());
153+
//Note: this method *does* flush. It is equivalent to:
154+
// OutputStreamWriter _out = new OutputStreamWriter(fout);
155+
// IOUtils.copy( str, _out, 4096 ); // copy( Reader, Writer, int );
156+
// _out.flush();
157+
// out = fout;
158+
// note: we don't flush here; this IOUtils method does it for us
159+
160+
assertEquals(inData.length, baout.size(), "Sizes differ");
161+
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
162+
}
163+
145164
@Test
146165
public void copy_stringToWriter() throws Exception {
147166
final String str = new String(inData, StandardCharsets.US_ASCII);

0 commit comments

Comments
 (0)