diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java index 1601ff921d..295ce15d9f 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java @@ -32,12 +32,14 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** - * Utility methods for working with {@link ContextLoader ContextLoaders}, - * resource locations and classes, and active bean definition profiles. + * Utility methods for working with {@link ContextLoader ContextLoaders} and + * {@link SmartContextLoader SmartContextLoaders} and resolving resource locations, + * configuration classes, and active bean definition profiles. * * @author Sam Brannen * @since 3.1 * @see ContextLoader + * @see SmartContextLoader * @see ContextConfiguration * @see ContextConfigurationAttributes * @see ActiveProfiles @@ -47,11 +49,31 @@ abstract class ContextLoaderUtils { private static final Log logger = LogFactory.getLog(ContextLoaderUtils.class); - private static final String STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.GenericXmlContextLoader"; + private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.GenericXmlContextLoader"; + private ContextLoaderUtils() { + /* no-op */ + } + /** - * TODO Document resolveContextConfigurationAttributes(). + * Resolve the list of {@link ContextConfigurationAttributes configuration + * attributes} for the supplied {@link Class class} and its superclasses. + *
Note that the {@link ContextConfiguration#inheritLocations
+ * inheritLocations} flag of {@link ContextConfiguration
+ * @ContextConfiguration} will be taken into consideration.
+ * Specifically, if the If the supplied This method will iterate over the supplied configuration attributes
+ * and execute the following algorithm:
* Note that the {@link ActiveProfiles#inheritProfiles() inheritProfiles}
+ * Resolve active bean definition profiles for the supplied {@link Class}.
+ * Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles}
* flag of {@link ActiveProfiles @ActiveProfiles} will be taken into
* consideration. Specifically, if the Note that the {@link ContextConfiguration#inheritLocations()
- * inheritLocations} flag of {@link ContextConfiguration
- * @ContextConfiguration} will be taken into consideration.
- * Specifically, if the inheritLocations
flag is set to
+ * true
, configuration attributes defined in the annotated
+ * class will be appended to the configuration attributes defined in
+ * superclasses.
+ * @param clazz the class for which to resolve the configuration attributes (must
+ * not be null
)
+ * @return the list of configuration attributes for the specified class,
+ * including configuration attributes from superclasses if appropriate
+ * (never null
)
+ * @throws IllegalArgumentException if the supplied class is null
+ * or if {@link ContextConfiguration @ContextConfiguration} is not
+ * present on the supplied class
*/
static ListContextLoader
.
- *
+ * Resolve the {@link ContextLoader} {@link Class class} to use for the
+ * supplied {@link Class testClass} and {@link ContextConfigurationAttributes}
+ * and then instantiate and return that {@code ContextLoader}.
* defaultContextLoaderClassName
is
* null
or empty, the standard
- * default context loader class name ({@value #STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME})
+ * default context loader class name {@value #DEFAULT_CONTEXT_LOADER_CLASS_NAME}
* will be used. For details on the class resolution process, see
- * {@link #resolveContextLoaderClass(Class, String)}.
- *
- * @param testClass the test class for which the ContextLoader
+ * {@link #resolveContextLoaderClass()}.
+ * @param testClass the test class for which the {@code ContextLoader}
* should be resolved (must not be null
)
- * @param configAttributesList TODO Document configAttributesList parameter
+ * @param configAttributesList the resolved configuration attributes for the
+ * test class hierarchy
* @param defaultContextLoaderClassName the name of the default
- * ContextLoader
class to use (may be null
)
- *
- * @return the resolved ContextLoader
for the supplied
+ * {@code ContextLoader} class to use (may be null
)
+ * @return the resolved {@code ContextLoader} for the supplied
* testClass
(never null
)
- * @see #resolveContextLoaderClass(Class, String)
+ * @see #resolveContextLoaderClass()
+ * @see #resolveContextConfigurationAttributes()
*/
static ContextLoader resolveContextLoader(Class> testClass,
List
- *
- *
- * @param testClass the class for which to resolve the loader
class is not specified, the class hierarchy
- * will be traversed to find a parent class annotated with
- * @ContextConfiguration
; go to step #1.loader
class is found after traversing
- * the class hierarchy, an attempt will be made to load and return the class
- * with the supplied defaultContextLoaderClassName
.loader
class is found after processing
+ * all {@link ContextConfigurationAttributes} instances, an attempt will be
+ * made to load and return the class with the supplied
+ * defaultContextLoaderClassName
.ContextLoader
- * class; must not be null
- * @param configAttributesList TODO Document configAttributesList parameter
+ * @param testClass the class for which to resolve the {@code ContextLoader}
+ * class; used solely for logging purposes; must not be null
+ * @param configAttributesList the resolved configuration attributes for the
+ * test class hierarchy; must not be null
or empty
* @param defaultContextLoaderClassName the name of the default
- * ContextLoader
class to use; must not be null
or empty
- *
- * @return the ContextLoader
class to use for the specified class
+ * {@code ContextLoader} class to use; must not be null
or empty
+ * @return the {@code ContextLoader} class to use for the specified class
* (never null
)
- * @throws IllegalArgumentException if {@link ContextConfiguration
- * @ContextConfiguration} is not present on the supplied class
+ * @throws IllegalArgumentException if {@code @ContextConfiguration} is not
+ * present on the supplied test class
+ * @see #resolveContextLoader()
+ * @see #resolveContextConfigurationAttributes()
*/
@SuppressWarnings("unchecked")
static Class extends ContextLoader> resolveContextLoaderClass(Class> testClass,
@@ -191,20 +214,18 @@ abstract class ContextLoaderUtils {
}
/**
- * Resolves active bean definition profiles for the supplied
- * {@link Class class}.
- *
- * inheritProfiles
flag is
* set to true
, profiles defined in the annotated class will be
* merged with those defined in superclasses.
- *
* @param clazz the class for which to resolve the active profiles (must
* not be null
)
- *
* @return the set of active profiles for the specified class, including
* active profiles from superclasses if appropriate (never null
)
+ * @see org.springframework.test.context.ActiveProfiles
+ * @see org.springframework.context.annotation.Profile
*/
static String[] resolveActiveProfiles(Class> clazz) {
Assert.notNull(clazz, "Class must not be null");
@@ -256,34 +277,21 @@ abstract class ContextLoaderUtils {
return StringUtils.toStringArray(activeProfiles);
}
- /*
- * Resolves {@link ApplicationContext} resource locations for the supplied
- * {@link Class class}, using the supplied {@link ContextLoader} to {@link
- * ContextLoader#processLocations(Class, String...) process} the locations.
- *
- * inheritLocations
flag is set to
- * true
, locations defined in the annotated class will be
- * appended to the locations defined in superclasses.
- *
- * @param contextLoader the ContextLoader to use for processing the
- * locations (must not be null
)
- *
- * @param clazz the class for which to resolve the resource locations (must
- * not be null
)
- *
- * @return the list of ApplicationContext resource locations for the
- * specified class, including locations from superclasses if appropriate
- * (never null
)
- *
- * @throws IllegalArgumentException if {@link ContextConfiguration
- * @ContextConfiguration} is not present on the supplied class
- */
-
/**
- * TODO Document buildMergedContextConfiguration().
+ * Build the {@link MergedContextConfiguration merged context configuration}
+ * for the supplied {@link Class testClass} and
+ * defaultContextLoaderClassName
.
+ * @param testClass the test class for which the {@code MergedContextConfiguration}
+ * should be built (must not be null
)
+ * @param defaultContextLoaderClassName the name of the default
+ * {@code ContextLoader} class to use (may be null
)
+ * @return the merged context configuration
+ * @see #resolveContextConfigurationAttributes()
+ * @see #resolveContextLoader()
+ * @see SmartContextLoader#processContextConfiguration()
+ * @see ContextLoader#processLocations()
+ * @see #resolveActiveProfiles()
+ * @see MergedContextConfiguration
*/
static MergedContextConfiguration buildMergedContextConfiguration(Class> testClass,
String defaultContextLoaderClassName) {