Skip to content

Commit df7c340

Browse files
committed
better test - comparing printer input and parser output
1 parent 8f98cf6 commit df7c340

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,18 +1564,24 @@ public void testTrim() throws Exception {
15641564

15651565
@Test
15661566
public void testParsingPrintedEmptyFirstColumn() throws Exception {
1567+
String[][] lines = new String[][] {
1568+
{"a", "b"},
1569+
{"", "x"}
1570+
};
15671571
Exception firstException = null;
15681572
for (CSVFormat.Predefined format : CSVFormat.Predefined.values()) {
15691573
try {
15701574
StringWriter buf = new StringWriter();
15711575
try (CSVPrinter printer = new CSVPrinter(buf, format.getFormat())) {
1572-
printer.printRecord("a", "b"); // header
1573-
printer.printRecord("", "x"); // empty first column
1576+
for (String[] line : lines) {
1577+
printer.printRecord((Object[]) line);
1578+
}
15741579
}
1575-
try (CSVParser csvRecords = new CSVParser(new StringReader(buf.toString()), format.getFormat().builder().setHeader().build())) {
1576-
for (CSVRecord csvRecord : csvRecords) {
1577-
assertNotNull(csvRecord);
1580+
try (CSVParser csvRecords = new CSVParser(new StringReader(buf.toString()), format.getFormat())) {
1581+
for (String[] line : lines) {
1582+
assertArrayEquals(line, csvRecords.nextRecord().values());
15781583
}
1584+
assertNull(csvRecords.nextRecord());
15791585
}
15801586
} catch (Exception | Error e) {
15811587
Exception detailedException = new RuntimeException("format: " + format, e);

0 commit comments

Comments
 (0)