3232import org .springframework .util .StringUtils ;
3333
3434/**
35- * Utility methods for working with {@link ContextLoader ContextLoaders},
36- * resource locations and classes, and active bean definition profiles.
35+ * Utility methods for working with {@link ContextLoader ContextLoaders} and
36+ * {@link SmartContextLoader SmartContextLoaders} and resolving resource locations,
37+ * configuration classes, and active bean definition profiles.
3738 *
3839 * @author Sam Brannen
3940 * @since 3.1
4041 * @see ContextLoader
42+ * @see SmartContextLoader
4143 * @see ContextConfiguration
4244 * @see ContextConfigurationAttributes
4345 * @see ActiveProfiles
@@ -47,11 +49,31 @@ abstract class ContextLoaderUtils {
4749
4850 private static final Log logger = LogFactory .getLog (ContextLoaderUtils .class );
4951
50- private static final String STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.GenericXmlContextLoader" ;
52+ private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.GenericXmlContextLoader" ;
5153
5254
55+ private ContextLoaderUtils () {
56+ /* no-op */
57+ }
58+
5359 /**
54- * TODO Document resolveContextConfigurationAttributes().
60+ * Resolve the list of {@link ContextConfigurationAttributes configuration
61+ * attributes} for the supplied {@link Class class} and its superclasses.
62+ * <p>Note that the {@link ContextConfiguration#inheritLocations
63+ * inheritLocations} flag of {@link ContextConfiguration
64+ * @ContextConfiguration} will be taken into consideration.
65+ * Specifically, if the <code>inheritLocations</code> flag is set to
66+ * <code>true</code>, configuration attributes defined in the annotated
67+ * class will be appended to the configuration attributes defined in
68+ * superclasses.
69+ * @param clazz the class for which to resolve the configuration attributes (must
70+ * not be <code>null</code>)
71+ * @return the list of configuration attributes for the specified class,
72+ * including configuration attributes from superclasses if appropriate
73+ * (never <code>null</code>)
74+ * @throws IllegalArgumentException if the supplied class is <code>null</code>
75+ * or if {@link ContextConfiguration @ContextConfiguration} is not
76+ * <em>present</em> on the supplied class
5577 */
5678 static List <ContextConfigurationAttributes > resolveContextConfigurationAttributes (Class <?> clazz ) {
5779 Assert .notNull (clazz , "Class must not be null" );
@@ -88,33 +110,32 @@ static List<ContextConfigurationAttributes> resolveContextConfigurationAttribute
88110 }
89111
90112 /**
91- * Resolves the {@link ContextLoader} {@link Class} to use for the
92- * supplied {@link Class testClass} and then instantiates and returns
93- * that <code>ContextLoader</code>.
94- *
113+ * Resolve the {@link ContextLoader} {@link Class class} to use for the
114+ * supplied {@link Class testClass} and {@link ContextConfigurationAttributes}
115+ * and then instantiate and return that {@code ContextLoader}.
95116 * <p>If the supplied <code>defaultContextLoaderClassName</code> is
96117 * <code>null</code> or <em>empty</em>, the <em>standard</em>
97- * default context loader class name ( {@value #STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME})
118+ * default context loader class name {@value #DEFAULT_CONTEXT_LOADER_CLASS_NAME}
98119 * will be used. For details on the class resolution process, see
99- * {@link #resolveContextLoaderClass(Class, String)}.
100- *
101- * @param testClass the test class for which the <code>ContextLoader</code>
120+ * {@link #resolveContextLoaderClass()}.
121+ * @param testClass the test class for which the {@code ContextLoader}
102122 * should be resolved (must not be <code>null</code>)
103- * @param configAttributesList TODO Document configAttributesList parameter
123+ * @param configAttributesList the resolved configuration attributes for the
124+ * test class hierarchy
104125 * @param defaultContextLoaderClassName the name of the default
105- * <code>ContextLoader</code> class to use (may be <code>null</code>)
106- *
107- * @return the resolved <code>ContextLoader</code> for the supplied
126+ * {@code ContextLoader} class to use (may be <code>null</code>)
127+ * @return the resolved {@code ContextLoader} for the supplied
108128 * <code>testClass</code> (never <code>null</code>)
109- * @see #resolveContextLoaderClass(Class, String)
129+ * @see #resolveContextLoaderClass()
130+ * @see #resolveContextConfigurationAttributes()
110131 */
111132 static ContextLoader resolveContextLoader (Class <?> testClass ,
112133 List <ContextConfigurationAttributes > configAttributesList , String defaultContextLoaderClassName ) {
113134 Assert .notNull (testClass , "Test class must not be null" );
114135 Assert .notEmpty (configAttributesList , "ContextConfigurationAttributes list must not be null or empty" );
115136
116137 if (!StringUtils .hasText (defaultContextLoaderClassName )) {
117- defaultContextLoaderClassName = STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME ;
138+ defaultContextLoaderClassName = DEFAULT_CONTEXT_LOADER_CLASS_NAME ;
118139 }
119140
120141 Class <? extends ContextLoader > contextLoaderClass = resolveContextLoaderClass (testClass , configAttributesList ,
@@ -124,31 +145,33 @@ static ContextLoader resolveContextLoader(Class<?> testClass,
124145 }
125146
126147 /**
127- * Resolves the {@link ContextLoader} {@link Class} to use for the supplied
128- * {@link Class test class}.
129- *
148+ * Resolve the {@link ContextLoader} {@link Class} to use for the supplied
149+ * {@link ContextConfigurationAttributes} list.
150+ * <p>This method will iterate over the supplied configuration attributes
151+ * and execute the following algorithm:
130152 * <ol>
131- * <li>If the {@link ContextConfiguration#loader() loader} attribute of
132- * {@link ContextConfiguration @ContextConfiguration} is configured
133- * with an explicit class, that class will be returned.</li>
134- * <li>If a <code>loader</code> class is not specified, the class hierarchy
135- * will be traversed to find a parent class annotated with
136- * <code>@ContextConfiguration </code>; go to step #1.</li>
137- * <li>If no explicit <code>loader</code> class is found after traversing
138- * the class hierarchy, an attempt will be made to load and return the class
139- * with the supplied <code>defaultContextLoaderClassName</code>.</li>
153+ * <li>If {@link ContextConfigurationAttributes#getContextLoaderClass()}
154+ * returns an explicit implementation class, that class will be returned.</li>
155+ * <li>If an explicit {@code ContextLoader} implementation class is not
156+ * specified, the next {@link ContextConfigurationAttributes} instance in
157+ * the supplied list will be processed; go to step #1.</li>
158+ * <li>If no explicit < code>loader </code> class is found after processing
159+ * all {@link ContextConfigurationAttributes} instances, an attempt will be
160+ * made to load and return the class with the supplied
161+ * <code>defaultContextLoaderClassName</code>.</li>
140162 * </ol>
141- *
142- * @param testClass the class for which to resolve the <code>ContextLoader </code>
143- * class; must not be <code>null</code>
144- * @param configAttributesList TODO Document configAttributesList parameter
163+ * @param testClass the class for which to resolve the {@code ContextLoader}
164+ * class; used solely for logging purposes; must not be <code>null </code>
165+ * @param configAttributesList the resolved configuration attributes for the
166+ * test class hierarchy; must not be <code>null</code> or empty
145167 * @param defaultContextLoaderClassName the name of the default
146- * <code>ContextLoader</code> class to use; must not be <code>null</code> or empty
147- *
148- * @return the <code>ContextLoader</code> class to use for the specified class
168+ * {@code ContextLoader} class to use; must not be <code>null</code> or empty
169+ * @return the {@code ContextLoader} class to use for the specified class
149170 * (never <code>null</code>)
150- * @throws IllegalArgumentException if {@link ContextConfiguration
151- * @ContextConfiguration} is not <em>present</em> on the supplied class
171+ * @throws IllegalArgumentException if {@code @ContextConfiguration} is not
172+ * <em>present</em> on the supplied test class
173+ * @see #resolveContextLoader()
174+ * @see #resolveContextConfigurationAttributes()
152175 */
153176 @ SuppressWarnings ("unchecked" )
154177 static Class <? extends ContextLoader > resolveContextLoaderClass (Class <?> testClass ,
@@ -191,20 +214,18 @@ static Class<? extends ContextLoader> resolveContextLoaderClass(Class<?> testCla
191214 }
192215
193216 /**
194- * Resolves <em>active bean definition profiles</em> for the supplied
195- * {@link Class class}.
196- *
197- * <p>Note that the {@link ActiveProfiles#inheritProfiles() inheritProfiles}
217+ * Resolve <em>active bean definition profiles</em> for the supplied {@link Class}.
218+ * <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles}
198219 * flag of {@link ActiveProfiles @ActiveProfiles} will be taken into
199220 * consideration. Specifically, if the <code>inheritProfiles</code> flag is
200221 * set to <code>true</code>, profiles defined in the annotated class will be
201222 * merged with those defined in superclasses.
202- *
203223 * @param clazz the class for which to resolve the active profiles (must
204224 * not be <code>null</code>)
205- *
206225 * @return the set of active profiles for the specified class, including
207226 * active profiles from superclasses if appropriate (never <code>null</code>)
227+ * @see org.springframework.test.context.ActiveProfiles
228+ * @see org.springframework.context.annotation.Profile
208229 */
209230 static String [] resolveActiveProfiles (Class <?> clazz ) {
210231 Assert .notNull (clazz , "Class must not be null" );
@@ -256,34 +277,21 @@ else if (!ObjectUtils.isEmpty(valueProfiles)) {
256277 return StringUtils .toStringArray (activeProfiles );
257278 }
258279
259- /*
260- * Resolves {@link ApplicationContext} resource locations for the supplied
261- * {@link Class class}, using the supplied {@link ContextLoader} to {@link
262- * ContextLoader#processLocations(Class, String...) process} the locations.
263- *
264- * <p>Note that the {@link ContextConfiguration#inheritLocations()
265- * inheritLocations} flag of {@link ContextConfiguration
266- * @ContextConfiguration} will be taken into consideration.
267- * Specifically, if the <code>inheritLocations</code> flag is set to
268- * <code>true</code>, locations defined in the annotated class will be
269- * appended to the locations defined in superclasses.
270- *
271- * @param contextLoader the ContextLoader to use for processing the
272- * locations (must not be <code>null</code>)
273- *
274- * @param clazz the class for which to resolve the resource locations (must
275- * not be <code>null</code>)
276- *
277- * @return the list of ApplicationContext resource locations for the
278- * specified class, including locations from superclasses if appropriate
279- * (never <code>null</code>)
280- *
281- * @throws IllegalArgumentException if {@link ContextConfiguration
282- * @ContextConfiguration} is not <em>present</em> on the supplied class
283- */
284-
285280 /**
286- * TODO Document buildMergedContextConfiguration().
281+ * Build the {@link MergedContextConfiguration merged context configuration}
282+ * for the supplied {@link Class testClass} and
283+ * <code>defaultContextLoaderClassName</code>.
284+ * @param testClass the test class for which the {@code MergedContextConfiguration}
285+ * should be built (must not be <code>null</code>)
286+ * @param defaultContextLoaderClassName the name of the default
287+ * {@code ContextLoader} class to use (may be <code>null</code>)
288+ * @return the merged context configuration
289+ * @see #resolveContextConfigurationAttributes()
290+ * @see #resolveContextLoader()
291+ * @see SmartContextLoader#processContextConfiguration()
292+ * @see ContextLoader#processLocations()
293+ * @see #resolveActiveProfiles()
294+ * @see MergedContextConfiguration
287295 */
288296 static MergedContextConfiguration buildMergedContextConfiguration (Class <?> testClass ,
289297 String defaultContextLoaderClassName ) {
0 commit comments