Skip to content

Commit 8a96d2b

Browse files
committed
Use Stream.toList() instead of Collector.toList() in tests
1 parent 3301075 commit 8a96d2b

File tree

12 files changed

+27
-38
lines changed

12 files changed

+27
-38
lines changed

jupiter-tests/src/test/java/org/junit/jupiter/api/condition/AbstractExecutionConditionTests.java

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

1111
package org.junit.jupiter.api.condition;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.junit.jupiter.api.Assertions.assertFalse;
1615
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -61,10 +60,10 @@ void ensureAllTestMethodsAreCovered() {
6160
Predicate<Method> isTestMethod = method -> method.isAnnotationPresent(Test.class);
6261

6362
List<String> methodsToTest = findMethods(getTestClass(), isTestMethod, TOP_DOWN).stream()//
64-
.map(Method::getName).sorted().collect(toList());
63+
.map(Method::getName).sorted().toList();
6564

6665
List<String> localTestMethods = findMethods(getClass(), isTestMethod, TOP_DOWN).stream()//
67-
.map(Method::getName).sorted().collect(toList());
66+
.map(Method::getName).sorted().toList();
6867

6968
assertThat(localTestMethods).isEqualTo(methodsToTest);
7069
}

jupiter-tests/src/test/java/org/junit/jupiter/api/extension/ExtensionComposabilityTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package org.junit.jupiter.api.extension;
1212

1313
import static java.util.function.Predicate.not;
14-
import static java.util.stream.Collectors.toList;
14+
import static java.util.stream.Collectors.toCollection;
1515
import static org.assertj.core.api.Assertions.assertThat;
1616
import static org.junit.jupiter.api.Assertions.assertAll;
1717
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -22,6 +22,7 @@
2222
import java.lang.reflect.Method;
2323
import java.lang.reflect.Modifier;
2424
import java.lang.reflect.Proxy;
25+
import java.util.ArrayList;
2526
import java.util.Arrays;
2627
import java.util.List;
2728
import java.util.stream.Stream;
@@ -60,18 +61,18 @@ void ensureJupiterExtensionApisAreComposable() {
6061
.flatMap(Arrays::stream)
6162
.filter(not(Method::isSynthetic))
6263
.filter(not(where(Method::getModifiers, Modifier::isStatic)))
63-
.collect(toList());
64+
.toList();
6465

6566
List<String> expectedMethodSignatures = expectedMethods.stream()
6667
.map(this::methodSignature)
6768
.sorted()
68-
.collect(toList());
69+
.toList();
6970

7071
List<String> expectedMethodNames = expectedMethods.stream()
7172
.map(Method::getName)
7273
.distinct()
7374
.sorted()
74-
.collect(toList());
75+
.toList();
7576
// @formatter:on
7677

7778
// 3) Dynamically implement all Extension APIs
@@ -83,19 +84,19 @@ void ensureJupiterExtensionApisAreComposable() {
8384
// @formatter:off
8485
List<Method> actualMethods = Arrays.stream(dynamicKitchenSinkExtension.getClass().getDeclaredMethods())
8586
.filter(ModifierSupport::isNotStatic)
86-
.collect(toList());
87+
.toList();
8788

8889
List<String> actualMethodSignatures = actualMethods.stream()
8990
.map(this::methodSignature)
9091
.distinct()
9192
.sorted()
92-
.collect(toList());
93+
.collect(toCollection(ArrayList::new));
9394

9495
List<String> actualMethodNames = actualMethods.stream()
9596
.map(Method::getName)
9697
.distinct()
9798
.sorted()
98-
.collect(toList());
99+
.collect(toCollection(ArrayList::new));
99100
// @formatter:on
100101

101102
// 5) Remove methods from java.lang.Object

jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptorTests.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.engine.descriptor;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.junit.jupiter.api.Assertions.assertEquals;
1615
import static org.mockito.Mockito.mock;
@@ -135,7 +134,7 @@ void constructFromMethodWithAnnotations() throws Exception {
135134
assertEquals("custom test name", methodDescriptor.getDisplayName(), "display name:");
136135
assertEquals("foo()", methodDescriptor.getLegacyReportingName(), "legacy name:");
137136

138-
List<String> tags = methodDescriptor.getTags().stream().map(TestTag::getName).collect(toList());
137+
List<String> tags = methodDescriptor.getTags().stream().map(TestTag::getName).toList();
139138
assertThat(tags).containsExactlyInAnyOrder("inherited-class-level-tag", "classTag1", "classTag2", "methodTag1",
140139
"methodTag2");
141140
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/LifecycleMethodUtilsTests.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.engine.descriptor;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.junit.jupiter.api.Assertions.assertEquals;
1615
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -131,7 +130,7 @@ void findAfterAllMethodsWithLifeCyclePerClassAndRequiringStatic() {
131130
}
132131

133132
private static List<String> namesOf(List<Method> methods) {
134-
return methods.stream().map(Method::getName).collect(toList());
133+
return methods.stream().map(Method::getName).toList();
135134
}
136135

137136
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoverySelectorResolverTests.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.discovery;
1212

1313
import static java.util.Collections.singleton;
14-
import static java.util.stream.Collectors.toList;
1514
import static org.assertj.core.api.Assertions.assertThat;
1615
import static org.junit.jupiter.api.Assertions.assertEquals;
1716
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -759,7 +758,7 @@ private TestDescriptor descriptorByUniqueId(UniqueId uniqueId) {
759758
}
760759

761760
private List<UniqueId> uniqueIds() {
762-
return engineDescriptor.getDescendants().stream().map(TestDescriptor::getUniqueId).collect(toList());
761+
return engineDescriptor.getDescendants().stream().map(TestDescriptor::getUniqueId).toList();
763762
}
764763

765764
private LauncherDiscoveryRequestBuilder request() {

platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
package org.junit.platform.commons.util;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.junit.jupiter.api.Assertions.assertEquals;
1615
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -273,8 +272,7 @@ void findRepeatableAnnotationsWithComposedTagBeforeContainer() {
273272
}
274273

275274
private void assertTagsFound(Class<?> clazz, String... tags) {
276-
assertEquals(List.of(tags),
277-
findRepeatableAnnotations(clazz, Tag.class).stream().map(Tag::value).collect(toList()),
275+
assertEquals(List.of(tags), findRepeatableAnnotations(clazz, Tag.class).stream().map(Tag::value).toList(),
278276
() -> "Tags found for class " + clazz.getName());
279277
}
280278

@@ -332,7 +330,7 @@ void findInheritedRepeatableAnnotationsWithMultipleComposedAnnotationsOnSupercla
332330

333331
private void assertExtensionsFound(Class<?> clazz, String... tags) {
334332
assertEquals(List.of(tags),
335-
findRepeatableAnnotations(clazz, ExtendWith.class).stream().map(ExtendWith::value).collect(toList()),
333+
findRepeatableAnnotations(clazz, ExtendWith.class).stream().map(ExtendWith::value).toList(),
336334
() -> "Extensions found for class " + clazz.getName());
337335
}
338336

@@ -610,7 +608,7 @@ void findPublicAnnotatedFieldsForDirectlyAnnotatedFieldsInClassAndInterface() {
610608
}
611609

612610
private List<String> asNames(List<Field> fields) {
613-
return fields.stream().map(Field::getName).collect(toList());
611+
return fields.stream().map(Field::getName).toList();
614612
}
615613

616614
// -------------------------------------------------------------------------

platform-tests/src/test/java/org/junit/platform/commons/util/CollectionUtilsTests.java

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

1111
package org.junit.platform.commons.util;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.junit.jupiter.api.Assertions.assertEquals;
1615
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -260,7 +259,7 @@ public Stream<String> stream() {
260259
};
261260

262261
try (var stream = (Stream<String>) CollectionUtils.toStream(input)) {
263-
var result = stream.collect(toList());
262+
var result = stream.toList();
264263
assertThat(result).containsExactly("foo", "bar");
265264
}
266265

platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import static java.time.Duration.ofMillis;
1414
import static java.util.Arrays.stream;
1515
import static java.util.stream.Collectors.joining;
16-
import static java.util.stream.Collectors.toList;
1716
import static org.assertj.core.api.Assertions.assertThat;
1817
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
1918
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -1645,7 +1644,7 @@ private static List<String> signaturesOf(List<Method> methods) {
16451644
// @formatter:off
16461645
return methods.stream()
16471646
.map(m -> String.format("%s(%s)", m.getName(), ClassUtils.nullSafeToString(m.getParameterTypes())))
1648-
.collect(toList());
1647+
.toList();
16491648
// @formatter:on
16501649
}
16511650

platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java

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

1313
import static java.util.concurrent.TimeUnit.MILLISECONDS;
14-
import static java.util.stream.Collectors.toList;
1514
import static org.assertj.core.api.Assertions.assertThat;
1615
import static org.junit.jupiter.api.Assertions.assertEquals;
1716
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -522,7 +521,7 @@ void b() throws Exception {
522521

523522
private List<Event> getEventsOfChildren(EngineExecutionResults results, TestDescriptor container) {
524523
return results.testEvents().filter(
525-
event -> event.getTestDescriptor().getParent().orElseThrow().equals(container)).collect(toList());
524+
event -> event.getTestDescriptor().getParent().orElseThrow().equals(container)).toList();
526525
}
527526

528527
private TestDescriptor findFirstTestDescriptor(EngineExecutionResults results, Condition<Event> condition) {
@@ -534,7 +533,7 @@ private List<Instant> getTimestampsFor(List<Event> events, Condition<Event> cond
534533
return events.stream()
535534
.filter(condition::matches)
536535
.map(Event::getTimestamp)
537-
.collect(toList());
536+
.toList();
538537
// @formatter:on
539538
}
540539

platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilderTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
package org.junit.platform.launcher.core;
1212

13-
import static java.util.stream.Collectors.toList;
1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.junit.jupiter.api.Assertions.assertThrows;
1615
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -64,7 +63,7 @@ void modulesAreStoredInDiscoveryRequest() {
6463
// @formatter:on
6564

6665
var packageSelectors = discoveryRequest.getSelectorsByType(ModuleSelector.class).stream().map(
67-
ModuleSelector::getModuleName).collect(toList());
66+
ModuleSelector::getModuleName).toList();
6867
assertThat(packageSelectors).contains("java.base");
6968
}
7069

@@ -78,7 +77,7 @@ void packagesAreStoredInDiscoveryRequest() {
7877
// @formatter:on
7978

8079
var packageSelectors = discoveryRequest.getSelectorsByType(PackageSelector.class).stream().map(
81-
PackageSelector::getPackageName).collect(toList());
80+
PackageSelector::getPackageName).toList();
8281
assertThat(packageSelectors).contains("org.junit.platform.engine");
8382
}
8483

@@ -94,7 +93,7 @@ void classesAreStoredInDiscoveryRequest() {
9493
// @formatter:on
9594

9695
List<Class<?>> classes = discoveryRequest.getSelectorsByType(ClassSelector.class).stream().map(
97-
ClassSelector::getJavaClass).collect(toList());
96+
ClassSelector::getJavaClass).toList();
9897
assertThat(classes).contains(SampleTestClass.class, LauncherDiscoveryRequestBuilderTests.class);
9998
}
10099

@@ -167,7 +166,7 @@ void uniqueIdsAreStoredInDiscoveryRequest() {
167166
// @formatter:on
168167

169168
var uniqueIds = discoveryRequest.getSelectorsByType(UniqueIdSelector.class).stream().map(
170-
UniqueIdSelector::getUniqueId).map(Object::toString).collect(toList());
169+
UniqueIdSelector::getUniqueId).map(Object::toString).toList();
171170

172171
assertThat(uniqueIds).contains(id1.toString(), id2.toString());
173172
}

0 commit comments

Comments
 (0)