[SPR-8387] refined logging.
This commit is contained in:
parent
4ef895a018
commit
19fc2004f5
|
@ -19,6 +19,7 @@ package org.springframework.test.context;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.core.style.ToStringCreator;
|
import org.springframework.core.style.ToStringCreator;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,14 +56,15 @@ public class ContextConfigurationAttributes {
|
||||||
* @throws IllegalStateException if both the locations and value attributes have been declared
|
* @throws IllegalStateException if both the locations and value attributes have been declared
|
||||||
*/
|
*/
|
||||||
static String[] resolveLocations(Class<?> declaringClass, ContextConfiguration contextConfiguration) {
|
static String[] resolveLocations(Class<?> declaringClass, ContextConfiguration contextConfiguration) {
|
||||||
|
Assert.notNull(declaringClass, "declaringClass must not be null");
|
||||||
|
|
||||||
String[] locations = contextConfiguration.locations();
|
String[] locations = contextConfiguration.locations();
|
||||||
String[] valueLocations = contextConfiguration.value();
|
String[] valueLocations = contextConfiguration.value();
|
||||||
|
|
||||||
if (!ObjectUtils.isEmpty(valueLocations) && !ObjectUtils.isEmpty(locations)) {
|
if (!ObjectUtils.isEmpty(valueLocations) && !ObjectUtils.isEmpty(locations)) {
|
||||||
String msg = String.format("Test class [%s] has been configured with @ContextConfiguration's 'value' [%s] "
|
String msg = String.format("Test class [%s] has been configured with @ContextConfiguration's 'value' %s "
|
||||||
+ "and 'locations' [%s] attributes. Only one declaration of resource "
|
+ "and 'locations' %s attributes. Only one declaration of resource "
|
||||||
+ "locations is permitted per @ContextConfiguration annotation.", declaringClass,
|
+ "locations is permitted per @ContextConfiguration annotation.", declaringClass.getName(),
|
||||||
ObjectUtils.nullSafeToString(valueLocations), ObjectUtils.nullSafeToString(locations));
|
ObjectUtils.nullSafeToString(valueLocations), ObjectUtils.nullSafeToString(locations));
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
|
|
|
@ -147,8 +147,8 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
|
||||||
if (configClasses.isEmpty()) {
|
if (configClasses.isEmpty()) {
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info(String.format("Cannot generate default configuration classes for test class [%s]: "
|
logger.info(String.format("Cannot generate default configuration classes for test class [%s]: "
|
||||||
+ "test class does not declare any static, non-private, non-final, inner classes "
|
+ "%s does not declare any static, non-private, non-final, inner classes "
|
||||||
+ "annotated with @Configuration.", declaringClass));
|
+ "annotated with @Configuration.", declaringClass.getName(), declaringClass.getSimpleName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue