Skip to content

Commit 7b2d29f

Browse files
committed
Add test for CSV parser using null as an empty value parser result
This commit describes and tests the status-quo of the current implementation that return `null` for empty CSV values. It might be changed in the future. Addresses #1014
1 parent 3008b90 commit 7b2d29f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
4141
settings.getFormat().setDelimiter(delimiter);
4242
settings.getFormat().setQuote('\'');
4343
settings.getFormat().setQuoteEscape('\'');
44+
settings.setEmptyValue(null); // see https://github.com/junit-team/junit5/issues/1014
4445
settings.setAutoConfigurationEnabled(false);
4546
CsvParser csvParser = new CsvParser(settings);
4647
AtomicLong index = new AtomicLong(0);

junit-jupiter-params/src/test/java/org/junit/jupiter/params/provider/CsvArgumentsProviderTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ void throwsExceptionOnInvalidCsv() {
6868
assertThat(exception).hasMessage("Line at index 2 contains invalid CSV: \"\"");
6969
}
7070

71+
@Test
72+
void emptyValueIsNull() {
73+
Stream<Object[]> arguments = provideArguments(',', "null , , empty , ''");
74+
75+
assertThat(arguments).containsExactly(new String[] { "null", null, "empty", null });
76+
}
77+
7178
private Stream<Object[]> provideArguments(char delimiter, String... value) {
7279
CsvSource annotation = mock(CsvSource.class);
7380
when(annotation.value()).thenReturn(value);

0 commit comments

Comments
 (0)