better test - comparing printer input and parser output
This commit is contained in:
parent
8f98cf634e
commit
df7c340e7b
|
@ -1564,19 +1564,25 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsingPrintedEmptyFirstColumn() throws Exception {
|
public void testParsingPrintedEmptyFirstColumn() throws Exception {
|
||||||
|
String[][] lines = new String[][] {
|
||||||
|
{"a", "b"},
|
||||||
|
{"", "x"}
|
||||||
|
};
|
||||||
Exception firstException = null;
|
Exception firstException = null;
|
||||||
for (CSVFormat.Predefined format : CSVFormat.Predefined.values()) {
|
for (CSVFormat.Predefined format : CSVFormat.Predefined.values()) {
|
||||||
try {
|
try {
|
||||||
StringWriter buf = new StringWriter();
|
StringWriter buf = new StringWriter();
|
||||||
try (CSVPrinter printer = new CSVPrinter(buf, format.getFormat())) {
|
try (CSVPrinter printer = new CSVPrinter(buf, format.getFormat())) {
|
||||||
printer.printRecord("a", "b"); // header
|
for (String[] line : lines) {
|
||||||
printer.printRecord("", "x"); // empty first column
|
printer.printRecord((Object[]) line);
|
||||||
}
|
|
||||||
try (CSVParser csvRecords = new CSVParser(new StringReader(buf.toString()), format.getFormat().builder().setHeader().build())) {
|
|
||||||
for (CSVRecord csvRecord : csvRecords) {
|
|
||||||
assertNotNull(csvRecord);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try (CSVParser csvRecords = new CSVParser(new StringReader(buf.toString()), format.getFormat())) {
|
||||||
|
for (String[] line : lines) {
|
||||||
|
assertArrayEquals(line, csvRecords.nextRecord().values());
|
||||||
|
}
|
||||||
|
assertNull(csvRecords.nextRecord());
|
||||||
|
}
|
||||||
} catch (Exception | Error e) {
|
} catch (Exception | Error e) {
|
||||||
Exception detailedException = new RuntimeException("format: " + format, e);
|
Exception detailedException = new RuntimeException("format: " + format, e);
|
||||||
if (firstException == null) {
|
if (firstException == null) {
|
||||||
|
|
Loading…
Reference in New Issue