Skip to content

Commit 72c405c

Browse files
committed
Replace Collectors.toList() with Stream.toList()
1 parent 2922d2d commit 72c405c

File tree

45 files changed

+67
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+67
-114
lines changed

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertAll.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Collection;
1515
import java.util.List;
1616
import java.util.Objects;
17-
import java.util.stream.Collectors;
1817
import java.util.stream.Stream;
1918

2019
import org.jspecify.annotations.Nullable;
@@ -75,7 +74,7 @@ static void assertAll(@Nullable String heading, Stream<Executable> executables)
7574
}
7675
}) //
7776
.filter(Objects::nonNull) //
78-
.collect(Collectors.toList());
77+
.toList();
7978

8079
if (!failures.isEmpty()) {
8180
MultipleFailuresError multipleFailuresError = new MultipleFailuresError(heading, failures);

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertLinesMatch.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Deque;
2020
import java.util.List;
2121
import java.util.regex.PatternSyntaxException;
22-
import java.util.stream.Collectors;
2322
import java.util.stream.IntStream;
2423
import java.util.stream.Stream;
2524

@@ -65,8 +64,8 @@ static void assertLinesMatch(Stream<String> expectedLines, Stream<String> actual
6564
return;
6665
}
6766

68-
List<String> expectedListOfStrings = expectedLines.collect(Collectors.toList());
69-
List<String> actualListOfStrings = actualLines.collect(Collectors.toList());
67+
List<String> expectedListOfStrings = expectedLines.toList();
68+
List<String> actualListOfStrings = actualLines.toList();
7069
assertLinesMatch(expectedListOfStrings, actualListOfStrings, messageOrSupplier);
7170
}
7271

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ClassTemplateTestDescriptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.junit.jupiter.engine.descriptor;
1212

1313
import static java.util.stream.Collectors.toCollection;
14-
import static java.util.stream.Collectors.toList;
1514
import static org.apiguardian.api.API.Status.INTERNAL;
1615
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD;
1716
import static org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.validateClassTemplateInvocationLifecycleMethodsAreDeclaredCorrectly;
@@ -108,9 +107,9 @@ protected JupiterTestDescriptor copyIncludingDescendants(UnaryOperator<UniqueId>
108107
copy.childrenPrototypes.add(newChild);
109108
});
110109
this.childrenPrototypesByIndex.forEach((index, oldChildren) -> {
111-
List<TestDescriptor> newChildren = oldChildren.stream() //
110+
List<? extends TestDescriptor> newChildren = oldChildren.stream() //
112111
.map(oldChild -> ((JupiterTestDescriptor) oldChild).copyIncludingDescendants(uniqueIdTransformer)) //
113-
.collect(toList());
112+
.toList();
114113
copy.childrenPrototypesByIndex.put(index, newChildren);
115114
});
116115
return copy;

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TemplateExecutor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
package org.junit.jupiter.engine.descriptor;
1212

13-
import static java.util.stream.Collectors.toList;
14-
1513
import java.util.List;
1614
import java.util.Optional;
1715
import java.util.concurrent.atomic.AtomicInteger;
@@ -81,7 +79,7 @@ private void executeForProvider(P provider, AtomicInteger invocationIndex,
8179
private List<P> validateProviders(ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) {
8280
List<P> providers = extensionRegistry.stream(providerType) //
8381
.filter(provider -> supports(provider, extensionContext)) //
84-
.collect(toList());
82+
.toList();
8583
return Preconditions.notEmpty(providers, this::getNoRegisteredProviderErrorMessage);
8684
}
8785

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/AbstractOrderingVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import static java.util.Comparator.comparing;
1414
import static java.util.Objects.requireNonNull;
1515
import static java.util.stream.Collectors.toCollection;
16-
import static java.util.stream.Collectors.toList;
1716

1817
import java.util.ArrayList;
1918
import java.util.HashMap;
@@ -110,11 +109,11 @@ protected <CHILD extends TestDescriptor, WRAPPER extends AbstractAnnotatedDescri
110109

111110
if (shouldNonMatchingDescriptorsComeBeforeOrderedOnes()) {
112111
return Stream.concat(nonMatchingTestDescriptors, orderedTestDescriptors)//
113-
.collect(toList());
112+
.toList();
114113
}
115114
else {
116115
return Stream.concat(orderedTestDescriptors, nonMatchingTestDescriptors)//
117-
.collect(toList());
116+
.toList();
118117
}
119118
});
120119
}

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/MethodSelectorResolver.java

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

1313
import static java.util.Collections.emptyList;
1414
import static java.util.Collections.emptySet;
15-
import static java.util.stream.Collectors.toList;
1615
import static java.util.stream.Collectors.toSet;
1716
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId;
1817
import static org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.matches;
@@ -105,7 +104,7 @@ private Resolution resolve(Context context, List<Class<?>> enclosingClasses, Cla
105104
"Possible configuration error: method [%s] resulted in multiple TestDescriptors %s. "
106105
+ "This is typically the result of annotating a method with multiple competing annotations "
107106
+ "such as @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, etc.",
108-
method.toGenericString(), testDescriptors.map(d -> d.getClass().getName()).collect(toList()));
107+
method.toGenericString(), testDescriptors.map(d -> d.getClass().getName()).toList());
109108
issueReporter.reportIssue(
110109
DiscoveryIssue.builder(Severity.WARNING, message).source(MethodSource.from(method)));
111110
}

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/ParameterResolutionUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.junit.jupiter.engine.execution;
1212

1313
import static java.util.stream.Collectors.joining;
14-
import static java.util.stream.Collectors.toList;
1514
import static org.apiguardian.api.API.Status.INTERNAL;
1615
import static org.junit.platform.commons.util.KotlinReflectionUtils.getKotlinSuspendingFunctionParameters;
1716
import static org.junit.platform.commons.util.KotlinReflectionUtils.isKotlinSuspendingFunction;
@@ -132,7 +131,7 @@ public class ParameterResolutionUtils {
132131
// @formatter:off
133132
List<ParameterResolver> matchingResolvers = extensionRegistry.stream(ParameterResolver.class)
134133
.filter(resolver -> resolver.supportsParameter(parameterContext, extensionContext.get(resolver)))
135-
.collect(toList());
134+
.toList();
136135
// @formatter:on
137136

138137
if (matchingResolvers.isEmpty()) {

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/MutableExtensionRegistry.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.Set;
2828
import java.util.function.Function;
2929
import java.util.function.Predicate;
30-
import java.util.stream.Collectors;
3130
import java.util.stream.Stream;
3231

3332
import org.apiguardian.api.API;
@@ -122,7 +121,7 @@ private static void logExcludedExtensions(List<Class<? extends Extension>> exclu
122121
List<String> excludeExtensionNames = excludedExtensions
123122
.stream()
124123
.map(Class::getName)
125-
.collect(Collectors.toList());
124+
.toList();
126125
// @formatter:on
127126
logger.config(() -> "Excluded auto-detected extensions due to configured includes/excludes: %s".formatted(
128127
excludeExtensionNames));

junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedClassInvocationContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
package org.junit.jupiter.params;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD;
1514

1615
import java.util.List;
@@ -42,7 +41,7 @@ public String getDisplayName(int invocationIndex) {
4241
@Override
4342
public List<Extension> getAdditionalExtensions() {
4443
return Stream.concat(Stream.of(createParameterInjector()), createLifecycleMethodInvokers()) //
45-
.collect(toList());
44+
.toList();
4645
}
4746

4847
@Override

junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import static java.lang.System.lineSeparator;
1414
import static java.util.Objects.requireNonNull;
1515
import static java.util.stream.Collectors.joining;
16-
import static java.util.stream.Collectors.toList;
1716
import static java.util.stream.Collectors.toMap;
1817
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
1918
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
@@ -402,7 +401,7 @@ private static void validateIndexedParameters(
402401

403402
private static void validateIndexedParameterDeclarations(int index, List<FieldParameterDeclaration> declarations,
404403
List<String> errors) {
405-
List<Field> fields = declarations.stream().map(FieldParameterDeclaration::getField).collect(toList());
404+
List<Field> fields = declarations.stream().map(FieldParameterDeclaration::getField).toList();
406405
if (index < 0) {
407406
declarations.stream() //
408407
.map(

0 commit comments

Comments
 (0)