diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index 7b62ee1e5e8..193d1441950 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -75,16 +76,15 @@ public abstract class TestPropertySourceUtils { static MergedTestPropertySources buildMergedTestPropertySources(Class testClass) { - List> mergedAnnotations = - findRepeatableAnnotations(testClass, TestPropertySource.class); + List attributesList = + findRepeatableAnnotations(testClass, TestPropertySource.class) + .map(TestPropertySourceAttributes::new) + .collect(Collectors.toList()); - if (mergedAnnotations.isEmpty()) { + if (attributesList.isEmpty()) { return MergedTestPropertySources.empty(); } - List attributesList = mergedAnnotations.stream() - .map(TestPropertySourceAttributes::new) - .collect(Collectors.toList()); return new MergedTestPropertySources(mergeLocations(attributesList), mergeProperties(attributesList)); } @@ -273,12 +273,12 @@ public abstract class TestPropertySourceUtils { return map; } - private static List> findRepeatableAnnotations( + private static Stream> findRepeatableAnnotations( Class clazz, Class annotationType) { List>> listOfLists = new ArrayList<>(); findRepeatableAnnotations(clazz, annotationType, listOfLists, new int[] {0}); - return listOfLists.stream().flatMap(List::stream).collect(Collectors.toList()); + return listOfLists.stream().flatMap(List::stream); } private static void findRepeatableAnnotations(