|
50 | 50 | import java.util.Map; |
51 | 51 | import java.util.NoSuchElementException; |
52 | 52 | import java.util.stream.Collectors; |
| 53 | +import java.util.stream.Stream; |
53 | 54 |
|
54 | 55 | import org.apache.commons.io.input.BOMInputStream; |
55 | 56 | import org.apache.commons.io.input.BrokenInputStream; |
| 57 | +import org.apache.commons.lang3.stream.Streams.FailableStream; |
56 | 58 | import org.junit.jupiter.api.Assertions; |
57 | 59 | import org.junit.jupiter.api.Disabled; |
58 | 60 | import org.junit.jupiter.api.Test; |
| 61 | +import org.junit.jupiter.params.ParameterizedTest; |
| 62 | +import org.junit.jupiter.params.provider.EnumSource; |
| 63 | +import org.junit.jupiter.params.provider.ValueSource; |
59 | 64 |
|
60 | 65 | /** |
61 | 66 | * CSVParserTest |
@@ -1380,36 +1385,19 @@ public void testParseWithQuoteWithEscape() throws IOException { |
1380 | 1385 | } |
1381 | 1386 | } |
1382 | 1387 |
|
1383 | | - @Test |
1384 | | - public void testParsingPrintedEmptyFirstColumn() throws Exception { |
| 1388 | + @ParameterizedTest |
| 1389 | + @EnumSource(CSVFormat.Predefined.class) |
| 1390 | + public void testParsingPrintedEmptyFirstColumn(final CSVFormat.Predefined format) throws Exception { |
1385 | 1391 | final String[][] lines = { { "a", "b" }, { "", "x" } }; |
1386 | | - Exception firstException = null; |
1387 | | - for (final CSVFormat.Predefined format : CSVFormat.Predefined.values()) { |
1388 | | - try { |
1389 | | - final StringWriter buf = new StringWriter(); |
1390 | | - try (CSVPrinter printer = new CSVPrinter(buf, format.getFormat())) { |
1391 | | - for (final String[] line : lines) { |
1392 | | - printer.printRecord((Object[]) line); |
1393 | | - } |
1394 | | - } |
1395 | | - try (CSVParser csvRecords = new CSVParser(new StringReader(buf.toString()), format.getFormat())) { |
1396 | | - for (final String[] line : lines) { |
1397 | | - assertArrayEquals(line, csvRecords.nextRecord().values()); |
1398 | | - } |
1399 | | - assertNull(csvRecords.nextRecord()); |
1400 | | - } |
1401 | | - } catch (Exception | Error e) { |
1402 | | - final Exception detailedException = new RuntimeException("format: " + format, e); |
1403 | | - if (firstException == null) { |
1404 | | - firstException = detailedException; |
1405 | | - } else { |
1406 | | - firstException.addSuppressed(detailedException); |
1407 | | - } |
1408 | | - } |
| 1392 | + final StringWriter buf = new StringWriter(); |
| 1393 | + try (CSVPrinter printer = new CSVPrinter(buf, format.getFormat())) { |
| 1394 | + printer.printRecords(Stream.of(lines)); |
1409 | 1395 | } |
1410 | | - |
1411 | | - if (firstException != null) { |
1412 | | - throw firstException; |
| 1396 | + try (CSVParser parser = new CSVParser(new StringReader(buf.toString()), format.getFormat())) { |
| 1397 | + for (final String[] line : lines) { |
| 1398 | + assertArrayEquals(line, parser.nextRecord().values()); |
| 1399 | + } |
| 1400 | + assertNull(parser.nextRecord()); |
1413 | 1401 | } |
1414 | 1402 | } |
1415 | 1403 |
|
|
0 commit comments