[SPR-5713] Added 'value' alias for @ContextConfiguration's 'locations' attribute.
This commit is contained in:
@@ -45,6 +45,13 @@ public @interface ContextConfiguration {
|
||||
*/
|
||||
String[] locations() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link #locations()}.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Whether or not {@link #locations() resource locations} from superclasses
|
||||
* should be <em>inherited</em>.
|
||||
|
||||
@@ -184,7 +184,25 @@ public class TestContext extends AttributeAccessorSupport {
|
||||
logger.trace("Retrieved @ContextConfiguration [" + contextConfiguration + "] for declaring class ["
|
||||
+ declaringClass + "]");
|
||||
}
|
||||
String[] locations = contextLoader.processLocations(declaringClass, contextConfiguration.locations());
|
||||
|
||||
String[] valueLocations = contextConfiguration.value();
|
||||
String[] locations = contextConfiguration.locations();
|
||||
if (!ObjectUtils.isEmpty(valueLocations) && !ObjectUtils.isEmpty(locations)) {
|
||||
String msg = "Test class ["
|
||||
+ declaringClass
|
||||
+ "] has been configured with @ContextConfiguration's 'value' ["
|
||||
+ ObjectUtils.nullSafeToString(valueLocations)
|
||||
+ "] and 'locations' ["
|
||||
+ ObjectUtils.nullSafeToString(locations)
|
||||
+ "] attributes. Only one declaration of resource locations is permitted per @ContextConfiguration annotation.";
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
else if (!ObjectUtils.isEmpty(valueLocations)) {
|
||||
locations = valueLocations;
|
||||
}
|
||||
|
||||
locations = contextLoader.processLocations(declaringClass, locations);
|
||||
locationsList.addAll(0, Arrays.<String> asList(locations));
|
||||
declaringClass = contextConfiguration.inheritLocations() ? AnnotationUtils.findAnnotationDeclaringClass(
|
||||
annotationType, declaringClass.getSuperclass()) : null;
|
||||
|
||||
Reference in New Issue
Block a user