Skip to content

Commit c0b6e1e

Browse files
committed
Delete CollectionUtils.toSet
1 parent 64de9f0 commit c0b6e1e

File tree

3 files changed

+7
-33
lines changed

3 files changed

+7
-33
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import static java.util.Objects.requireNonNull;
1414
import static org.junit.jupiter.params.provider.CsvParserFactory.createParserFor;
15-
import static org.junit.platform.commons.util.CollectionUtils.toSet;
1615

1716
import java.io.StringReader;
1817
import java.lang.annotation.Annotation;
@@ -43,7 +42,7 @@ class CsvArgumentsProvider extends AnnotationBasedArgumentsProvider<CsvSource> {
4342
@Override
4443
protected Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters, ExtensionContext context,
4544
CsvSource csvSource) {
46-
Set<String> nullValues = toSet(csvSource.nullValues());
45+
Set<String> nullValues = Set.of(csvSource.nullValues());
4746
CsvParser csvParser = createParserFor(csvSource);
4847
final boolean textBlockDeclared = !csvSource.textBlock().isEmpty();
4948
Preconditions.condition(csvSource.value().length > 0 ^ textBlockDeclared,
@@ -59,11 +58,11 @@ private Stream<Arguments> parseTextBlock(CsvSource csvSource, CsvParser csvParse
5958
List<Arguments> argumentsList = new ArrayList<>();
6059

6160
try {
62-
List<String[]> csvRecords = csvParser.parseAll(new StringReader(textBlock));
61+
List<@Nullable String[]> csvRecords = csvParser.parseAll(new StringReader(textBlock));
6362
String[] headers = useHeadersInDisplayName ? getHeaders(csvParser) : null;
6463

6564
AtomicInteger index = new AtomicInteger(0);
66-
for (String[] csvRecord : csvRecords) {
65+
for (var csvRecord : csvRecords) {
6766
index.incrementAndGet();
6867
Preconditions.notNull(csvRecord,
6968
() -> "Record at index " + index + " contains invalid CSV: \"\"\"\n" + textBlock + "\n\"\"\"");
@@ -116,8 +115,8 @@ static String[] getHeaders(CsvParser csvParser) {
116115
* {@link Named} if necessary (for CSV header support), and returns the
117116
* CSV record wrapped in an {@link Arguments} instance.
118117
*/
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) {
121120

122121
// Nothing to process?
123122
if (nullValues.isEmpty() && !useHeadersInDisplayName) {
@@ -132,7 +131,7 @@ static Arguments processCsvRecord(String[] csvRecord, Set<String> nullValues, bo
132131
Object[] arguments = new Object[csvRecord.length];
133132
for (int i = 0; i < csvRecord.length; i++) {
134133
Object column = csvRecord[i];
135-
if (nullValues.contains(column)) {
134+
if (column != null && nullValues.contains(column)) {
136135
column = null;
137136
}
138137
if (useHeadersInDisplayName) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.junit.jupiter.params.provider.CsvArgumentsProvider.handleCsvException;
1919
import static org.junit.jupiter.params.provider.CsvArgumentsProvider.processCsvRecord;
2020
import static org.junit.jupiter.params.provider.CsvParserFactory.createParserFor;
21-
import static org.junit.platform.commons.util.CollectionUtils.toSet;
2221

2322
import java.io.IOException;
2423
import java.io.InputStream;
@@ -125,7 +124,7 @@ private static class CsvParserIterator implements Iterator<Arguments> {
125124
this.csvParser = csvParser;
126125
this.csvFileSource = csvFileSource;
127126
this.useHeadersInDisplayName = csvFileSource.useHeadersInDisplayName();
128-
this.nullValues = toSet(csvFileSource.nullValues());
127+
this.nullValues = Set.of(csvFileSource.nullValues());
129128
advance();
130129
}
131130

junit-platform-commons/src/main/java/org/junit/platform/commons/util/CollectionUtils.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
import java.util.Arrays;
2424
import java.util.Collection;
2525
import java.util.Collections;
26-
import java.util.HashSet;
2726
import java.util.Iterator;
2827
import java.util.List;
2928
import java.util.ListIterator;
3029
import java.util.Optional;
31-
import java.util.Set;
3230
import java.util.function.Consumer;
3331
import java.util.stream.Collector;
3432
import java.util.stream.DoubleStream;
@@ -96,28 +94,6 @@ private CollectionUtils() {
9694
: collection.iterator().next();
9795
}
9896

99-
/**
100-
* Convert the supplied array of values to a {@link Set}.
101-
*
102-
* @param values the array of values; never {@code null}
103-
* @return a set of the values
104-
* @throws PreconditionViolationException if the array is {@code null}
105-
* @since 1.6
106-
*/
107-
@API(status = INTERNAL, since = "1.6")
108-
public static <T extends @Nullable Object> Set<T> toSet(T[] values) {
109-
Preconditions.notNull(values, "values array must not be null");
110-
if (values.length == 0) {
111-
return Collections.emptySet();
112-
}
113-
if (values.length == 1) {
114-
return Collections.singleton(values[0]);
115-
}
116-
var set = new HashSet<T>();
117-
Collections.addAll(set, values);
118-
return set;
119-
}
120-
12197
/**
12298
* Return a {@code Collector} that accumulates the input elements into a
12399
* new unmodifiable list, in encounter order.

0 commit comments

Comments
 (0)