12
12
13
13
import static java .util .Objects .requireNonNull ;
14
14
import static org .junit .jupiter .params .provider .CsvParserFactory .createParserFor ;
15
- import static org .junit .platform .commons .util .CollectionUtils .toSet ;
16
15
17
16
import java .io .StringReader ;
18
17
import java .lang .annotation .Annotation ;
@@ -43,7 +42,7 @@ class CsvArgumentsProvider extends AnnotationBasedArgumentsProvider<CsvSource> {
43
42
@ Override
44
43
protected Stream <? extends Arguments > provideArguments (ParameterDeclarations parameters , ExtensionContext context ,
45
44
CsvSource csvSource ) {
46
- Set <String > nullValues = toSet (csvSource .nullValues ());
45
+ Set <String > nullValues = Set . of (csvSource .nullValues ());
47
46
CsvParser csvParser = createParserFor (csvSource );
48
47
final boolean textBlockDeclared = !csvSource .textBlock ().isEmpty ();
49
48
Preconditions .condition (csvSource .value ().length > 0 ^ textBlockDeclared ,
@@ -59,11 +58,11 @@ private Stream<Arguments> parseTextBlock(CsvSource csvSource, CsvParser csvParse
59
58
List <Arguments > argumentsList = new ArrayList <>();
60
59
61
60
try {
62
- List <String []> csvRecords = csvParser .parseAll (new StringReader (textBlock ));
61
+ List <@ Nullable String []> csvRecords = csvParser .parseAll (new StringReader (textBlock ));
63
62
String [] headers = useHeadersInDisplayName ? getHeaders (csvParser ) : null ;
64
63
65
64
AtomicInteger index = new AtomicInteger (0 );
66
- for (String [] csvRecord : csvRecords ) {
65
+ for (var csvRecord : csvRecords ) {
67
66
index .incrementAndGet ();
68
67
Preconditions .notNull (csvRecord ,
69
68
() -> "Record at index " + index + " contains invalid CSV: \" \" \" \n " + textBlock + "\n \" \" \" " );
@@ -116,8 +115,8 @@ static String[] getHeaders(CsvParser csvParser) {
116
115
* {@link Named} if necessary (for CSV header support), and returns the
117
116
* CSV record wrapped in an {@link Arguments} instance.
118
117
*/
119
- static Arguments processCsvRecord (String [] csvRecord , Set <String > nullValues , boolean useHeadersInDisplayName ,
120
- String @ Nullable [] headers ) {
118
+ static Arguments processCsvRecord (@ Nullable String [] csvRecord , Set <String > nullValues ,
119
+ boolean useHeadersInDisplayName , String @ Nullable [] headers ) {
121
120
122
121
// Nothing to process?
123
122
if (nullValues .isEmpty () && !useHeadersInDisplayName ) {
@@ -132,7 +131,7 @@ static Arguments processCsvRecord(String[] csvRecord, Set<String> nullValues, bo
132
131
Object [] arguments = new Object [csvRecord .length ];
133
132
for (int i = 0 ; i < csvRecord .length ; i ++) {
134
133
Object column = csvRecord [i ];
135
- if (nullValues .contains (column )) {
134
+ if (column != null && nullValues .contains (column )) {
136
135
column = null ;
137
136
}
138
137
if (useHeadersInDisplayName ) {
0 commit comments