diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java b/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java index 0c191e467b..6f87fb0289 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java @@ -16,9 +16,6 @@ package org.springframework.test.context.support; -import java.util.Set; -import java.util.TreeSet; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,7 +23,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfilesResolver; import org.springframework.test.context.TestContextAnnotationUtils.AnnotationDescriptor; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; import static org.springframework.test.context.TestContextAnnotationUtils.findAnnotationDescriptor; @@ -43,6 +39,8 @@ import static org.springframework.test.context.TestContextAnnotationUtils.findAn */ public class DefaultActiveProfilesResolver implements ActiveProfilesResolver { + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + private static final Log logger = LogFactory.getLog(DefaultActiveProfilesResolver.class); @@ -58,36 +56,24 @@ public class DefaultActiveProfilesResolver implements ActiveProfilesResolver { @Override public String[] resolve(Class testClass) { Assert.notNull(testClass, "Class must not be null"); - - Set activeProfiles = new TreeSet<>(); - - Class annotationType = ActiveProfiles.class; - AnnotationDescriptor descriptor = findAnnotationDescriptor(testClass, annotationType); + AnnotationDescriptor descriptor = findAnnotationDescriptor(testClass, ActiveProfiles.class); if (descriptor == null) { if (logger.isDebugEnabled()) { logger.debug(String.format( "Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]", - annotationType.getName(), testClass.getName())); + ActiveProfiles.class.getName(), testClass.getName())); } + return EMPTY_STRING_ARRAY; } else { - Class declaringClass = descriptor.getDeclaringClass(); ActiveProfiles annotation = descriptor.synthesizeAnnotation(); - if (logger.isTraceEnabled()) { logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation, - declaringClass.getName())); - } - - for (String profile : annotation.profiles()) { - if (StringUtils.hasText(profile)) { - activeProfiles.add(profile.trim()); - } + descriptor.getDeclaringClass().getName())); } + return annotation.profiles(); } - - return StringUtils.toStringArray(activeProfiles); } }