[SPR-7326] MergedContextConfiguration now ensures that it holds non-null arrays with proper semantics for TestContext's cache key generation.
This commit is contained in:
parent
3f58da1cd6
commit
dbe96b5cf9
|
|
@ -18,9 +18,9 @@ package org.springframework.test.context;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
@ -243,10 +243,7 @@ abstract class ContextLoaderUtils {
|
||||||
annotationType, clazz));
|
annotationType, clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active profiles must be sorted due to cache key generation in
|
final Set<String> activeProfiles = new HashSet<String>();
|
||||||
// TestContext. Specifically, profile sets {foo,bar} and {bar,foo}
|
|
||||||
// must both result in the same array (e.g., [bar,foo]).
|
|
||||||
final SortedSet<String> activeProfiles = new TreeSet<String>();
|
|
||||||
|
|
||||||
while (declaringClass != null) {
|
while (declaringClass != null) {
|
||||||
ActiveProfiles annotation = declaringClass.getAnnotation(annotationType);
|
ActiveProfiles annotation = declaringClass.getAnnotation(annotationType);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.test.context;
|
package org.springframework.test.context;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.springframework.core.style.ToStringCreator;
|
import org.springframework.core.style.ToStringCreator;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO [SPR-8386] Document MergedContextConfiguration.
|
* TODO [SPR-8386] Document MergedContextConfiguration.
|
||||||
|
|
@ -40,6 +45,26 @@ public class MergedContextConfiguration {
|
||||||
private final ContextLoader contextLoader;
|
private final ContextLoader contextLoader;
|
||||||
|
|
||||||
|
|
||||||
|
private static String[] processLocations(String[] locations) {
|
||||||
|
return locations == null ? new String[] {} : locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?>[] processClasses(Class<?>[] classes) {
|
||||||
|
return classes == null ? new Class<?>[] {} : classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] processActiveProfiles(String[] activeProfiles) {
|
||||||
|
if (activeProfiles == null) {
|
||||||
|
return new String[] {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active profiles must be unique and sorted due to cache key generation
|
||||||
|
// in TestContext. Specifically, profile sets {foo,bar} and {bar,foo}
|
||||||
|
// must both result in the same array (e.g., [bar,foo]).
|
||||||
|
SortedSet<String> sortedProfilesSet = new TreeSet<String>(Arrays.asList(activeProfiles));
|
||||||
|
return StringUtils.toStringArray(sortedProfilesSet);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO Document MergedContextConfiguration constructor.
|
* TODO Document MergedContextConfiguration constructor.
|
||||||
*
|
*
|
||||||
|
|
@ -52,9 +77,9 @@ public class MergedContextConfiguration {
|
||||||
public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes,
|
public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes,
|
||||||
String[] activeProfiles, ContextLoader contextLoader) {
|
String[] activeProfiles, ContextLoader contextLoader) {
|
||||||
this.testClass = testClass;
|
this.testClass = testClass;
|
||||||
this.locations = locations;
|
this.locations = processLocations(locations);
|
||||||
this.classes = classes;
|
this.classes = processClasses(classes);
|
||||||
this.activeProfiles = activeProfiles;
|
this.activeProfiles = processActiveProfiles(activeProfiles);
|
||||||
this.contextLoader = contextLoader;
|
this.contextLoader = contextLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue