diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index d7885f67..bfa0951c 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -1538,6 +1538,28 @@ public class CSVPrinterTest { } } + @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(); } diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index cd29d591..deef5c6a 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -301,4 +301,12 @@ public class CSVRecordTest { 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")); + } }