[SPR-6104] @TestExecutionListeners now supports a 'listeners' alias for its existing 'value' attribute.
This commit is contained in:
@@ -245,13 +245,10 @@ public class TestContext extends AttributeAccessorSupport {
|
||||
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.";
|
||||
String msg = String.format(
|
||||
"Test class [%s] has been configured with @ContextConfiguration's 'value' [%s] and 'locations' [%s] attributes. Only one declaration of resource locations is permitted per @ContextConfiguration annotation.",
|
||||
declaringClass, ObjectUtils.nullSafeToString(valueLocations),
|
||||
ObjectUtils.nullSafeToString(locations));
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -201,9 +202,23 @@ public class TestContextManager {
|
||||
logger.trace("Retrieved @TestExecutionListeners [" + testExecutionListeners
|
||||
+ "] for declaring class [" + declaringClass + "].");
|
||||
}
|
||||
Class<? extends TestExecutionListener>[] classes = testExecutionListeners.value();
|
||||
if (classes != null) {
|
||||
classesList.addAll(0, Arrays.<Class<? extends TestExecutionListener>> asList(classes));
|
||||
|
||||
Class<? extends TestExecutionListener>[] valueListenerClasses = testExecutionListeners.value();
|
||||
Class<? extends TestExecutionListener>[] listenerClasses = testExecutionListeners.listeners();
|
||||
if (!ObjectUtils.isEmpty(valueListenerClasses) && !ObjectUtils.isEmpty(listenerClasses)) {
|
||||
String msg = String.format(
|
||||
"Test class [%s] has been configured with @TestExecutionListeners' 'value' [%s] and 'listeners' [%s] attributes. Use one or the other, but not both.",
|
||||
declaringClass, ObjectUtils.nullSafeToString(valueListenerClasses),
|
||||
ObjectUtils.nullSafeToString(listenerClasses));
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
else if (!ObjectUtils.isEmpty(valueListenerClasses)) {
|
||||
listenerClasses = valueListenerClasses;
|
||||
}
|
||||
|
||||
if (listenerClasses != null) {
|
||||
classesList.addAll(0, Arrays.<Class<? extends TestExecutionListener>> asList(listenerClasses));
|
||||
}
|
||||
declaringClass = (testExecutionListeners.inheritListeners() ? AnnotationUtils.findAnnotationDeclaringClass(
|
||||
annotationType, declaringClass.getSuperclass())
|
||||
|
||||
@@ -52,7 +52,12 @@ public @interface TestExecutionListeners {
|
||||
* @see org.springframework.test.context.support.DirtiesContextTestExecutionListener
|
||||
* @see org.springframework.test.context.transaction.TransactionalTestExecutionListener
|
||||
*/
|
||||
Class<? extends TestExecutionListener>[] value();
|
||||
Class<? extends TestExecutionListener>[] listeners() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link #listeners() listeners}.
|
||||
*/
|
||||
Class<? extends TestExecutionListener>[] value() default {};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user