Polishing

This commit is contained in:
Sam Brannen
2016-03-08 15:18:21 +01:00
parent 504779e210
commit 93fb7be783
5 changed files with 111 additions and 86 deletions

View File

@@ -28,13 +28,14 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MultiValueMap;
import static org.springframework.beans.BeanUtils.*;
import static org.springframework.beans.BeanUtils.instantiateClass;
/**
* {@code BootstrapUtils} is a collection of utility methods to assist with
* bootstrapping the <em>Spring TestContext Framework</em>.
*
* @author Sam Brannen
* @author Phillip Webb
* @since 4.1
* @see BootstrapWith
* @see BootstrapContext
@@ -44,14 +45,14 @@ abstract class BootstrapUtils {
private static final String DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME = "org.springframework.test.context.support.DefaultBootstrapContext";
private static final String DEFAULT_WEB_BOOTSTRAP_CONTEXT_CLASS_NAME = "org.springframework.test.context.web.WebTestContextBootstrapper";
private static final String WEB_APP_CONFIGURATION_ANNOTATION = "org.springframework.test.context.web.WebAppConfiguration";
private static final String DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME = "org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate";
private static final String DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME = "org.springframework.test.context.support.DefaultTestContextBootstrapper";
private static final String DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME = "org.springframework.test.context.web.WebTestContextBootstrapper";
private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME = "org.springframework.test.context.web.WebAppConfiguration";
private static final Log logger = LogFactory.getLog(BootstrapUtils.class);
@@ -116,8 +117,12 @@ abstract class BootstrapUtils {
* <p>If the {@link BootstrapWith @BootstrapWith} annotation is present on
* the test class, either directly or as a meta-annotation, then its
* {@link BootstrapWith#value value} will be used as the bootstrapper type.
* Otherwise, the {@link org.springframework.test.context.support.DefaultTestContextBootstrapper
* DefaultTestContextBootstrapper} will be used.
* Otherwise, either the
* {@link org.springframework.test.context.support.DefaultTestContextBootstrapper
* DefaultTestContextBootstrapper} or the
* {@link org.springframework.test.context.web.WebTestContextBootstrapper
* WebTestContextBootstrapper} will be used, depending on the presence of
* {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration}.
*
* @param bootstrapContext the bootstrap context to use
* @return a fully configured {@code TestContextBootstrapper}
@@ -151,6 +156,9 @@ abstract class BootstrapUtils {
}
}
/**
* @since 4.3
*/
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) {
MultiValueMap<String, Object> attributesMultiMap = AnnotatedElementUtils.getAllAnnotationAttributes(
testClass, BootstrapWith.class.getName());
@@ -163,11 +171,13 @@ abstract class BootstrapUtils {
return (Class<?>) values.get(0);
}
private static Class<?> resolveDefaultTestContextBootstrapper(Class<?> testClass)
throws Exception {
/**
* @since 4.3
*/
private static Class<?> resolveDefaultTestContextBootstrapper(Class<?> testClass) throws Exception {
ClassLoader classLoader = BootstrapUtils.class.getClassLoader();
if (AnnotatedElementUtils.isAnnotated(testClass, WEB_APP_CONFIGURATION_ANNOTATION)) {
return ClassUtils.forName(DEFAULT_WEB_BOOTSTRAP_CONTEXT_CLASS_NAME, classLoader);
if (AnnotatedElementUtils.isAnnotated(testClass, WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME)) {
return ClassUtils.forName(DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME, classLoader);
}
return ClassUtils.forName(DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME, classLoader);
}

View File

@@ -29,8 +29,8 @@ import java.lang.annotation.Target;
* should be a {@link org.springframework.web.context.WebApplicationContext
* WebApplicationContext}.
*
* <p>The mere presence of {@code @WebAppConfiguration} on a test class ensures
* that a {@code WebApplicationContext} will be loaded for the test using a default
* <p>The presence of {@code @WebAppConfiguration} on a test class indicates that
* a {@code WebApplicationContext} should be loaded for the test using a default
* for the path to the root of the web application. To override the default,
* specify an explicit resource path via the {@link #value} attribute.
*