Add missing test CopyUtils#testCopy_readerToOutputStreamString()
@@ -224,6 +224,28 @@ public void testCopy_readerToOutputStream() throws Exception {
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();
