Skip to content

Commit 70c9418

Browse files
committed
Convert new test into a proper JUnit test
1 parent 4224a32 commit 70c9418

1 file changed

Lines changed: 16 additions & 28 deletions

File tree

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@
5050
import java.util.Map;
5151
import java.util.NoSuchElementException;
5252
import java.util.stream.Collectors;
53+
import java.util.stream.Stream;
5354

5455
import org.apache.commons.io.input.BOMInputStream;
5556
import org.apache.commons.io.input.BrokenInputStream;
57+
import org.apache.commons.lang3.stream.Streams.FailableStream;
5658
import org.junit.jupiter.api.Assertions;
5759
import org.junit.jupiter.api.Disabled;
5860
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;
5964

6065
/**
6166
* CSVParserTest
@@ -1380,36 +1385,19 @@ public void testParseWithQuoteWithEscape() throws IOException {
13801385
}
13811386
}
13821387

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 {
13851391
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));
14091395
}
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());
14131401
}
14141402
}
14151403

0 commit comments

Comments
 (0)