From ef7ab768e73dba6ad9975ad0ae82401f697cd365 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 17 Aug 2022 12:03:10 +0200 Subject: [PATCH] Polishing --- .../test/context/util/TestContextResourceUtils.java | 5 +++-- .../test/context/TestExecutionListenersTests.java | 2 +- .../test/context/cache/LruContextCacheTests.java | 5 ++--- .../junit/jupiter/event/DefaultPublishedEvents.java | 5 ++--- .../junit/jupiter/event/PublishedEvents.java | 13 +------------ 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/util/TestContextResourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/util/TestContextResourceUtils.java index b931d987cf..0b67301989 100644 --- a/spring-test/src/main/java/org/springframework/test/context/util/TestContextResourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/util/TestContextResourceUtils.java @@ -16,6 +16,7 @@ package org.springframework.test.context.util; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -135,13 +136,13 @@ public abstract class TestContextResourceUtils { * the given {@link ResourceLoader}. * @param resourceLoader the {@code ResourceLoader} to use to convert the paths * @param paths the paths to be converted - * @return a new list of resources + * @return a new, mutable list of resources * @since 4.2 * @see #convertToResources(ResourceLoader, String...) * @see #convertToClasspathResourcePaths */ public static List convertToResourceList(ResourceLoader resourceLoader, String... paths) { - return stream(resourceLoader, paths).collect(Collectors.toList()); + return stream(resourceLoader, paths).collect(Collectors.toCollection(ArrayList::new)); } private static Stream stream(ResourceLoader resourceLoader, String... paths) { diff --git a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java index d0d8084423..b07d790797 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java @@ -200,7 +200,7 @@ class TestExecutionListenersTests { } private List names(List> classes) { - return classes.stream().map(Class::getSimpleName).collect(toList()); + return classes.stream().map(Class::getSimpleName).toList(); } private void assertRegisteredListeners(Class testClass, List> expected) { diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java index a34d49c395..47f7c98ad6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.util.ReflectionTestUtils; import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.Mockito.mock; @@ -166,7 +165,7 @@ class LruContextCacheTests { List actualNames = contextMap.keySet().stream() .map(cfg -> cfg.getClasses()[0]) .map(Class::getSimpleName) - .collect(toList()); + .toList(); // @formatter:on assertThat(actualNames).isEqualTo(asList(expectedNames)); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/DefaultPublishedEvents.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/DefaultPublishedEvents.java index 5d3b67f658..7e3c146258 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/DefaultPublishedEvents.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/DefaultPublishedEvents.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.util.Iterator; import java.util.List; import java.util.function.Function; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.springframework.test.context.event.ApplicationEventsHolder; @@ -51,7 +50,7 @@ class DefaultPublishedEvents implements PublishedEvents { } static SimpleTypedPublishedEvents of(Stream stream) { - return new SimpleTypedPublishedEvents<>(stream.collect(Collectors.toList())); + return new SimpleTypedPublishedEvents<>(stream.toList()); } @Override diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/PublishedEvents.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/PublishedEvents.java index 19c8abe07a..a505b4d124 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/PublishedEvents.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/PublishedEvents.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.test.context.junit.jupiter.event; -import java.util.Arrays; import java.util.function.Function; import java.util.function.Predicate; @@ -30,16 +29,6 @@ import java.util.function.Predicate; */ public interface PublishedEvents { - /** - * Creates a new {@link PublishedEvents} instance for the given events. - * - * @param events must not be {@literal null} - * @return will never be {@literal null} - */ - public static PublishedEvents of(Object... events) { - return of(Arrays.asList(events)); - } - /** * Returns all application events of the given type that were fired during the test execution. *