Skip to content

Commit b0955d6

Browse files
author
Gary Gregory
committed
Add missing test CopyUtils#testCopy_readerToOutputStreamString()
1 parent 2cf9118 commit b0955d6

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,28 @@ public void testCopy_readerToOutputStream() throws Exception {
224224
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
225225
}
226226

227+
@SuppressWarnings("resource") // 'in' is deliberately not closed
228+
@Test
229+
public void testCopy_readerToOutputStreamString() throws Exception {
230+
InputStream in = new ByteArrayInputStream(inData);
231+
in = new ThrowOnCloseInputStream(in);
232+
final Reader reader = new java.io.InputStreamReader(in, StandardCharsets.US_ASCII);
233+
234+
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
235+
final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true);
236+
237+
CopyUtils.copy(reader, out, StandardCharsets.US_ASCII.name());
238+
//Note: this method *does* flush. It is equivalent to:
239+
// OutputStreamWriter _out = new OutputStreamWriter(fout);
240+
// IOUtils.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
241+
// _out.flush();
242+
// out = fout;
243+
244+
// Note: rely on the method to flush
245+
assertEquals(inData.length, baout.size(), "Sizes differ");
246+
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
247+
}
248+
227249
@Test
228250
public void testCtor() {
229251
new CopyUtils();

0 commit comments

Comments
 (0)