@@ -58,12 +58,6 @@ public class CopyUtilsTest {
5858 // Tests
5959 // ----------------------------------------------------------------
6060
61- @ Test
62- public void testCtor () {
63- new CopyUtils ();
64- // Nothing to assert, the constructor is public and does not blow up.
65- }
66-
6761 @ Test
6862 public void copy_byteArrayToOutputStream () throws Exception {
6963 final ByteArrayOutputStream baout = new ByteArrayOutputStream ();
@@ -88,32 +82,6 @@ public void copy_byteArrayToWriter() throws Exception {
8882 assertArrayEquals (inData , baout .toByteArray (), "Content differs" );
8983 }
9084
91- @ Test
92- public void testCopy_byteArrayToWriterWithEncoding () throws Exception {
93- final String inDataStr = "data" ;
94- final String charsetName = "UTF-8" ;
95- final StringWriter writer = new StringWriter ();
96- CopyUtils .copy (inDataStr .getBytes (charsetName ), writer , charsetName );
97- assertEquals (inDataStr , writer .toString ());
98- }
99-
100- @ SuppressWarnings ("resource" ) // 'in' is deliberately not closed
101- @ Test
102- public void testCopy_inputStreamToOutputStream () throws Exception {
103- InputStream in = new ByteArrayInputStream (inData );
104- in = new ThrowOnCloseInputStream (in );
105-
106- final ByteArrayOutputStream baout = new ByteArrayOutputStream ();
107- final OutputStream out = new ThrowOnFlushAndCloseOutputStream (baout , false , true );
108-
109- final int count = CopyUtils .copy (in , out );
110-
111- assertEquals (0 , in .available (), "Not all bytes were read" );
112- assertEquals (inData .length , baout .size (), "Sizes differ" );
113- assertArrayEquals (inData , baout .toByteArray (), "Content differs" );
114- assertEquals (inData .length , count );
115- }
116-
11785 @ SuppressWarnings ("resource" ) // 'in' is deliberately not closed
11886 @ Test
11987 public void copy_inputStreamToWriter () throws Exception {
@@ -141,28 +109,6 @@ public void copy_inputStreamToWriterWithEncoding() throws Exception {
141109 assertEquals (inDataStr , writer .toString ());
142110 }
143111
144- @ SuppressWarnings ("resource" ) // 'in' is deliberately not closed
145- @ Test
146- public void testCopy_readerToOutputStream () throws Exception {
147- InputStream in = new ByteArrayInputStream (inData );
148- in = new ThrowOnCloseInputStream (in );
149- final Reader reader = new java .io .InputStreamReader (in , StandardCharsets .US_ASCII );
150-
151- final ByteArrayOutputStream baout = new ByteArrayOutputStream ();
152- final OutputStream out = new ThrowOnFlushAndCloseOutputStream (baout , false , true );
153-
154- CopyUtils .copy (reader , out );
155- //Note: this method *does* flush. It is equivalent to:
156- // OutputStreamWriter _out = new OutputStreamWriter(fout);
157- // IOUtils.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
158- // _out.flush();
159- // out = fout;
160-
161- // Note: rely on the method to flush
162- assertEquals (inData .length , baout .size (), "Sizes differ" );
163- assertArrayEquals (inData , baout .toByteArray (), "Content differs" );
164- }
165-
166112 @ SuppressWarnings ("resource" ) // 'in' is deliberately not closed
167113 @ Test
168114 public void copy_readerToWriter () throws Exception {
@@ -215,4 +161,58 @@ public void copy_stringToWriter() throws Exception {
215161 assertArrayEquals (inData , baout .toByteArray (), "Content differs" );
216162 }
217163
164+ @ Test
165+ public void testCopy_byteArrayToWriterWithEncoding () throws Exception {
166+ final String inDataStr = "data" ;
167+ final String charsetName = "UTF-8" ;
168+ final StringWriter writer = new StringWriter ();
169+ CopyUtils .copy (inDataStr .getBytes (charsetName ), writer , charsetName );
170+ assertEquals (inDataStr , writer .toString ());
171+ }
172+
173+ @ SuppressWarnings ("resource" ) // 'in' is deliberately not closed
174+ @ Test
175+ public void testCopy_inputStreamToOutputStream () throws Exception {
176+ InputStream in = new ByteArrayInputStream (inData );
177+ in = new ThrowOnCloseInputStream (in );
178+
179+ final ByteArrayOutputStream baout = new ByteArrayOutputStream ();
180+ final OutputStream out = new ThrowOnFlushAndCloseOutputStream (baout , false , true );
181+
182+ final int count = CopyUtils .copy (in , out );
183+
184+ assertEquals (0 , in .available (), "Not all bytes were read" );
185+ assertEquals (inData .length , baout .size (), "Sizes differ" );
186+ assertArrayEquals (inData , baout .toByteArray (), "Content differs" );
187+ assertEquals (inData .length , count );
188+ }
189+
190+ @ SuppressWarnings ("resource" ) // 'in' is deliberately not closed
191+ @ Test
192+ public void testCopy_readerToOutputStream () throws Exception {
193+ InputStream in = new ByteArrayInputStream (inData );
194+ in = new ThrowOnCloseInputStream (in );
195+ final Reader reader = new java .io .InputStreamReader (in , StandardCharsets .US_ASCII );
196+
197+ final ByteArrayOutputStream baout = new ByteArrayOutputStream ();
198+ final OutputStream out = new ThrowOnFlushAndCloseOutputStream (baout , false , true );
199+
200+ CopyUtils .copy (reader , out );
201+ //Note: this method *does* flush. It is equivalent to:
202+ // OutputStreamWriter _out = new OutputStreamWriter(fout);
203+ // IOUtils.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
204+ // _out.flush();
205+ // out = fout;
206+
207+ // Note: rely on the method to flush
208+ assertEquals (inData .length , baout .size (), "Sizes differ" );
209+ assertArrayEquals (inData , baout .toByteArray (), "Content differs" );
210+ }
211+
212+ @ Test
213+ public void testCtor () {
214+ new CopyUtils ();
215+ // Nothing to assert, the constructor is public and does not blow up.
216+ }
217+
218218} // CopyUtilsTest
0 commit comments