From 2eee56d0e21b8b7a2b0f094d7203f5c380496fa3 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 14 Oct 2020 15:03:22 +0200 Subject: [PATCH] Polish TestPropertySourceUtils --- .../support/TestPropertySourceUtils.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) 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 e5e938633e3..7b62ee1e5e8 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 @@ -75,11 +75,8 @@ public abstract class TestPropertySourceUtils { static MergedTestPropertySources buildMergedTestPropertySources(Class testClass) { - return mergeTestPropertySources(findRepeatableAnnotations(testClass, TestPropertySource.class)); - } - - private static MergedTestPropertySources mergeTestPropertySources( - List> mergedAnnotations) { + List> mergedAnnotations = + findRepeatableAnnotations(testClass, TestPropertySource.class); if (mergedAnnotations.isEmpty()) { return MergedTestPropertySources.empty(); @@ -287,20 +284,15 @@ public abstract class TestPropertySourceUtils { private static void findRepeatableAnnotations( Class clazz, Class annotationType, List>> listOfLists, int[] aggregateIndex) { + // Ensure we have a list for the current aggregate index. + if (listOfLists.size() < aggregateIndex[0] + 1) { + listOfLists.add(new ArrayList<>()); + } + MergedAnnotations.from(clazz, SearchStrategy.DIRECT) .stream(annotationType) .sorted(highMetaDistancesFirst()) - .forEach(annotation -> { - List> current = null; - if (listOfLists.size() < aggregateIndex[0] + 1) { - current = new ArrayList<>(); - listOfLists.add(current); - } - else { - current = listOfLists.get(aggregateIndex[0]); - } - current.add(0, annotation); - }); + .forEach(annotation -> listOfLists.get(aggregateIndex[0]).add(0, annotation)); aggregateIndex[0]++;