diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java index 2f414deff15..63aca620643 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java @@ -18,6 +18,7 @@ package org.springframework.test.context; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.apache.commons.logging.Log; @@ -252,7 +253,15 @@ abstract class ContextLoaderUtils { profiles = valueProfiles; } - profilesList.addAll(0, Arrays. asList(profiles)); + if (!ObjectUtils.isEmpty(profiles)) { + Collections.reverse(Arrays. asList(profiles)); + + for (String profile : profiles) { + if (StringUtils.hasText(profile)) { + profilesList.add(0, profile); + } + } + } declaringClass = activateProfiles.inheritProfiles() ? AnnotationUtils.findAnnotationDeclaringClass( annotationType, declaringClass.getSuperclass()) : null;