Skip to content

Commit cda6405

Browse files
committed
Add tests to cover use of the IOUtils class.
Requires the CSVFormat to have no quote or escape character, and the formatted value to be a java.io.Reader.
1 parent 293e57d commit cda6405

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.File;
3131
import java.io.IOException;
3232
import java.io.PrintStream;
33+
import java.io.Reader;
3334
import java.io.StringReader;
3435
import java.io.StringWriter;
3536
import java.io.Writer;
@@ -1471,4 +1472,31 @@ private String[] toFirstRecordValues(final String expected, final CSVFormat form
14711472
return CSVParser.parse(expected, format).getRecords().get(0).values();
14721473
}
14731474

1475+
@Test
1476+
public void testPrintReaderWithoutQuoteToWriter() throws IOException {
1477+
// Test to target the use of IOUtils::copyLarge.
1478+
// Requires the format to have no quote or escape character,
1479+
// value to be a java.io.Reader and the output to be a java.io.Writer.
1480+
final StringWriter sw = new StringWriter();
1481+
final String content = "testValue";
1482+
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) {
1483+
final StringReader value = new StringReader(content);
1484+
printer.print(value);
1485+
}
1486+
assertEquals(content, sw.toString());
1487+
}
1488+
1489+
@Test
1490+
public void testPrintReaderWithoutQuoteToAppendable() throws IOException {
1491+
// Test to target the use of IOUtils::copy.
1492+
// Requires the format to have no quote or escape character,
1493+
// value to be a java.io.Reader and the output to not be a java.io.Writer.
1494+
final StringBuilder sb = new StringBuilder();
1495+
final String content = "testValue";
1496+
try (final CSVPrinter printer = new CSVPrinter(sb, CSVFormat.DEFAULT.withQuote(null))) {
1497+
final StringReader value = new StringReader(content);
1498+
printer.print(value);
1499+
}
1500+
assertEquals(content, sb.toString());
1501+
}
14741502
}

0 commit comments

Comments
 (0)