From 285c92bb03fca6d2a0cdceed1e99df0699df3a2d Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 18 Aug 2023 16:33:30 +0200 Subject: [PATCH] Store reversedMetaDistance Comparator in static field --- .../test/context/support/TestPropertySourceUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 ff2f28c4b7b..40f6c709342 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 @@ -79,6 +79,9 @@ public abstract class TestPropertySourceUtils { private static final PropertySourceFactory defaultPropertySourceFactory = new DefaultPropertySourceFactory(); + private static Comparator> reversedMetaDistance = + Comparator.> comparingInt(MergedAnnotation::getDistance).reversed(); + private static final Log logger = LogFactory.getLog(TestPropertySourceUtils.class); @@ -426,7 +429,7 @@ public abstract class TestPropertySourceUtils { MergedAnnotations.from(clazz, SearchStrategy.DIRECT) .stream(annotationType) - .sorted(highMetaDistancesFirst()) + .sorted(reversedMetaDistance) .forEach(annotation -> listOfLists.get(aggregateIndex[0]).add(0, annotation)); aggregateIndex[0]++; @@ -448,10 +451,6 @@ public abstract class TestPropertySourceUtils { } } - private static Comparator> highMetaDistancesFirst() { - return Comparator.> comparingInt(MergedAnnotation::getDistance).reversed(); - } - /** * Extension of {@link Properties} that mimics a {@code SequencedMap} by * tracking all added properties in the supplied {@link LinkedHashMap}.