Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,28 @@ public void testTrimOnTwoColumns() throws IOException {
}
}

@Test
public void testNotFlushable() throws IOException {
final Appendable out = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT)) {
printer.printRecord("a", "b", "c");
assertEquals("a,b,c" + recordSeparator, out.toString());
printer.flush();
}
}

@Test
public void testCRComment() throws IOException {
final StringWriter sw = new StringWriter();
final Object value = "abc";
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) {
printer.print(value);
printer.printComment("This is a comment\r\non multiple lines\rthis is next comment\r");
assertEquals("abc" + recordSeparator + "# This is a comment" + recordSeparator + "# on multiple lines"
+ recordSeparator + "# this is next comment" + recordSeparator + "# " + recordSeparator, sw.toString());
}
}

private String[] toFirstRecordValues(final String expected, final CSVFormat format) throws IOException {
return CSVParser.parse(expected, format).getRecords().get(0).values();
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/apache/commons/csv/CSVRecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,12 @@ public void testGetWithEnum() {
assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
}

@Test
public void testCSVRecordNULLValues() throws IOException {
final CSVParser parser = CSVParser.parse("A,B\r\nONE,TWO", CSVFormat.DEFAULT.withHeader());
final CSVRecord csvRecord = new CSVRecord(parser, null, null, 0L, 0L);
assertEquals(0, csvRecord.size());
assertThrows(IllegalArgumentException.class, () -> csvRecord.get("B"));
}
}