Improve record and printer Coverage (#66)
* Improve CSVRecord and CSVPrinter coverage * remove useless test code and test throws * add space
This commit is contained in:
parent
6c66ca4704
commit
83b2b9cc2c
|
@ -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 {
|
private String[] toFirstRecordValues(final String expected, final CSVFormat format) throws IOException {
|
||||||
return CSVParser.parse(expected, format).getRecords().get(0).values();
|
return CSVParser.parse(expected, format).getRecords().get(0).values();
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,4 +301,12 @@ public class CSVRecordTest {
|
||||||
assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
|
assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
|
||||||
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue