Skip to content

Commit 8698ec2

Browse files
committed
Even though CopyUtils is deprecated, bring it to 100% code coverage.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1021986 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2ee073f commit 8698ec2

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
@@ -20,6 +20,7 @@
2020
import java.io.InputStream;
2121
import java.io.OutputStream;
2222
import java.io.Reader;
23+
import java.io.StringWriter;
2324
import java.io.Writer;
2425
import 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

Comments
 (0)