2020import java .io .InputStream ;
2121import java .io .OutputStream ;
2222import java .io .Reader ;
23+ import java .io .StringWriter ;
2324import java .io .Writer ;
2425import java .util .Arrays ;
2526
@@ -73,6 +74,11 @@ public void tearDown() throws Exception {
7374 // Tests
7475 // ----------------------------------------------------------------
7576
77+ public void testCtor () {
78+ new CopyUtils ();
79+ // Nothing to assert, the constructor is public and does not blow up.
80+ }
81+
7682 public void testCopy_byteArrayToOutputStream () throws Exception {
7783 ByteArrayOutputStream baout = new ByteArrayOutputStream ();
7884 OutputStream out = new YellOnFlushAndCloseOutputStream (baout , false , true );
@@ -95,6 +101,14 @@ public void testCopy_byteArrayToWriter() throws Exception {
95101 assertTrue ("Content differs" , Arrays .equals (inData , baout .toByteArray ()));
96102 }
97103
104+ public void testCopy_byteArrayToWriterWithEncoding () throws Exception {
105+ String inDataStr = "data" ;
106+ String charsetName = "UTF-8" ;
107+ StringWriter writer = new StringWriter ();
108+ CopyUtils .copy (inDataStr .getBytes (charsetName ), writer , charsetName );
109+ assertEquals (inDataStr , writer .toString ());
110+ }
111+
98112 public void testCopy_inputStreamToOutputStream () throws Exception {
99113 InputStream in = new ByteArrayInputStream (inData );
100114 in = new YellOnCloseInputStream (in );
@@ -126,6 +140,14 @@ public void testCopy_inputStreamToWriter() throws Exception {
126140 assertTrue ("Content differs" , Arrays .equals (inData , baout .toByteArray ()));
127141 }
128142
143+ public void testCopy_inputStreamToWriterWithEncoding () throws Exception {
144+ String inDataStr = "data" ;
145+ String charsetName = "UTF-8" ;
146+ StringWriter writer = new StringWriter ();
147+ CopyUtils .copy (new ByteArrayInputStream (inDataStr .getBytes (charsetName )), writer , charsetName );
148+ assertEquals (inDataStr , writer .toString ());
149+ }
150+
129151 public void testCopy_readerToOutputStream () throws Exception {
130152 InputStream in = new ByteArrayInputStream (inData );
131153 in = new YellOnCloseInputStream (in );
0 commit comments