diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java index 77ce7fbb791538dd634432440b18f1ab0fffac21..c4fcf8a221f1c20dcbcfb779f8e54902f22f34d8 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java @@ -131,17 +131,23 @@ public abstract class AbstractContextLoader implements SmartContextLoader { String suffix = getResourceSuffix(); Assert.hasText(suffix, "Resource suffix must not be empty"); String resourcePath = SLASH + ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix; + String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath; + ClassPathResource classPathResource = new ClassPathResource(resourcePath, clazz); - if (!new ClassPathResource(resourcePath, clazz).exists()) { + if (classPathResource.exists()) { if (logger.isInfoEnabled()) { - logger.info(String.format("Could not detect default resource locations for test class [%s]: " - + "classpath resource [%s] does not exist.", clazz.getName(), resourcePath)); + logger.info(String.format("Detected default resource location \"%s\" for test class [%s].", + prefixedResourcePath, clazz.getName())); } - return EMPTY_STRING_ARRAY; + return new String[] { prefixedResourcePath }; } // else - return new String[] { ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath }; + if (logger.isInfoEnabled()) { + logger.info(String.format("Could not detect default resource locations for test class [%s]: " + + "%s does not exist.", clazz.getName(), classPathResource)); + } + return EMPTY_STRING_ARRAY; } /** diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java index c68c10a68adbf1750d7c183c76fa6666dcc5c8a0..2915cf96a0ef2ed5b07c44dd04aafbaee50bf0f0 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java @@ -54,7 +54,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Delegating to %s to process context configuration [%s].", name(loader), + logger.debug(String.format("Delegating to %s to process context configuration %s.", name(loader), configAttributes)); } loader.processContextConfiguration(configAttributes); @@ -77,7 +77,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { if (configAttributes.hasLocations() && configAttributes.hasClasses()) { throw new IllegalStateException(String.format( "Cannot process locations AND configuration classes for context " - + "configuration [%s]; configure one or the other, but not both.", configAttributes)); + + "configuration %s; configure one or the other, but not both.", configAttributes)); } // If the original locations or classes were not empty, there's no @@ -98,14 +98,14 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { if (xmlLoaderDetectedDefaults) { if (logger.isInfoEnabled()) { - logger.info(String.format("%s detected default locations for context configuration [%s].", + logger.info(String.format("%s detected default locations for context configuration %s.", name(xmlLoader), configAttributes)); } } if (configAttributes.hasClasses()) { throw new IllegalStateException(String.format( - "%s should NOT have detected default configuration classes for context configuration [%s].", + "%s should NOT have detected default configuration classes for context configuration %s.", name(xmlLoader), configAttributes)); } @@ -115,28 +115,28 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { if (configAttributes.hasClasses()) { if (logger.isInfoEnabled()) { logger.info(String.format( - "%s detected default configuration classes for context configuration [%s].", + "%s detected default configuration classes for context configuration %s.", name(annotationLoader), configAttributes)); } } if (!xmlLoaderDetectedDefaults && configAttributes.hasLocations()) { throw new IllegalStateException(String.format( - "%s should NOT have detected default locations for context configuration [%s].", + "%s should NOT have detected default locations for context configuration %s.", name(annotationLoader), configAttributes)); } // If neither loader detected defaults, throw an exception. if (!configAttributes.hasResources()) { throw new IllegalStateException(String.format( - "Neither %s nor %s was able to detect defaults for context configuration [%s].", name(xmlLoader), + "Neither %s nor %s was able to detect defaults for context configuration %s.", name(xmlLoader), name(annotationLoader), configAttributes)); } if (configAttributes.hasLocations() && configAttributes.hasClasses()) { String message = String.format( "Configuration error: both default locations AND default configuration classes " - + "were detected for context configuration [%s]; configure one or the other, but not both.", + + "were detected for context configuration %s; configure one or the other, but not both.", configAttributes); logger.error(message); throw new IllegalStateException(message); @@ -157,15 +157,14 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { for (SmartContextLoader loader : candidates) { if (supports(loader, mergedConfig)) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Delegating to %s to load context from [%s].", name(loader), - mergedConfig)); + logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig)); } return loader.loadContext(mergedConfig); } } throw new IllegalStateException(String.format( - "Neither %s nor %s was able to load an ApplicationContext from [%s].", name(xmlLoader), + "Neither %s nor %s was able to load an ApplicationContext from %s.", name(xmlLoader), name(annotationLoader), mergedConfig)); } diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java index 4b53ea00daf9bfa7d5451b52e65f789c8da37c80..dc9121085b7dca7f27a9c64dafe9e6e4a22b2490 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java @@ -172,6 +172,10 @@ public class DelegatingSmartContextLoaderTests { return new String("foo"); } } + + static class NotAConfigClass { + + } } static class ImproperDuplicateDefaultXmlAndConfigClassTestCase { diff --git a/org.springframework.test/src/test/resources/log4j.xml b/org.springframework.test/src/test/resources/log4j.xml index d9a255f08a46207a5b85f84d940039a403854646..326b5d0d2ea9b8a728710a20b181485975ba8ff9 100644 --- a/org.springframework.test/src/test/resources/log4j.xml +++ b/org.springframework.test/src/test/resources/log4j.xml @@ -21,14 +21,16 @@ + - +