From 5628c8cd63b64e7620f01dbc1269f5984906289a Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 3 Nov 2020 14:46:17 +0100 Subject: [PATCH] Polish ActiveProfilesUtils --- .../test/context/support/ActiveProfilesUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java index 927cd9acc4..2354de61bd 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java @@ -17,7 +17,6 @@ package org.springframework.test.context.support; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -110,15 +109,15 @@ abstract class ActiveProfilesUtils { String[] profiles = resolver.resolve(rootDeclaringClass); if (!ObjectUtils.isEmpty(profiles)) { - profileArrays.add(profiles); + // Prepend to the list so that we can later traverse "down" the hierarchy + // to ensure that we retain the top-down profile registration order + // within a test class hierarchy. + profileArrays.add(0, profiles); } descriptor = (annotation.inheritProfiles() ? descriptor.next() : null); } - // Reverse the list so that we can traverse "down" the hierarchy. - Collections.reverse(profileArrays); - Set activeProfiles = new LinkedHashSet<>(); for (String[] profiles : profileArrays) { for (String profile : profiles) {