Skip to content

Commit 72da569

Browse files
committed
[SPR-8386][SPR-8387] Revised Javadoc in the TestContext framework regarding changes in 3.1.
1 parent 1c7cc17 commit 72da569

File tree

10 files changed

+87
-76
lines changed

10 files changed

+87
-76
lines changed

org.springframework.test/src/main/java/org/springframework/test/context/ActiveProfiles.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
public @interface ActiveProfiles {
4545

4646
/**
47-
* Alias for {@link #profiles() profiles}.
47+
* Alias for {@link #profiles}.
4848
*
4949
* <p>This attribute may <strong>not</strong> be used in conjunction
5050
* with {@link #profiles}, but it may be used <em>instead</em> of

org.springframework.test/src/main/java/org/springframework/test/context/ContextCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ ApplicationContext remove(MergedContextConfiguration key) {
158158
* {@link #remove removing} the context from the cache and explicitly
159159
* {@link ConfigurableApplicationContext#close() closing} it if
160160
* it is an instance of {@link ConfigurableApplicationContext}.
161-
* <p>Generally speaking, you would only call this method only if you change
162-
* the state of a singleton bean, potentially affecting future interaction
163-
* with the context.
161+
* <p>Generally speaking, you would only call this method if you change the
162+
* state of a singleton bean, potentially affecting future interaction with
163+
* the context.
164164
* @param key the context key (never <code>null</code>)
165165
* @see #remove
166166
*/

org.springframework.test/src/main/java/org/springframework/test/context/ContextConfiguration.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
* @since 2.5
4242
* @see ContextLoader
4343
* @see SmartContextLoader
44+
* @see ContextConfigurationAttributes
45+
* @see MergedContextConfiguration
4446
* @see org.springframework.context.ApplicationContext
4547
* @see ActiveProfiles
4648
*/
@@ -51,7 +53,7 @@
5153
public @interface ContextConfiguration {
5254

5355
/**
54-
* Alias for {@link #locations() locations}.
56+
* Alias for {@link #locations}.
5557
*
5658
* <p>This attribute may <strong>not</strong> be used in conjunction
5759
* with {@link #locations} or {@link #classes}, but it may be used
@@ -64,7 +66,7 @@
6466
* The resource locations to use for loading an
6567
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
6668
*
67-
* <p>Check out the javadoc for
69+
* <p>Check out the Javadoc for
6870
* {@link org.springframework.test.context.support.AbstractContextLoader#modifyLocations
6971
* AbstractContextLoader.modifyLocations()} for details on how a location
7072
* String will be interpreted at runtime, in particular in case of a relative
@@ -78,7 +80,9 @@
7880
* AbstractContextLoader} subclass such as
7981
* {@link org.springframework.test.context.support.GenericXmlContextLoader
8082
* GenericXmlContextLoader} which is the effective default implementation
81-
* used at runtime.
83+
* used at runtime if <code>locations</code> are configured. See the
84+
* documentation for {@link #loader} for further details regarding default
85+
* loaders.
8286
*
8387
* <p>This attribute may <strong>not</strong> be used in conjunction with
8488
* {@link #value} or {@link #classes}, but it may be used instead of
@@ -88,20 +92,16 @@
8892
String[] locations() default {};
8993

9094
/**
91-
* The {@link org.springframework.context.annotation.Configuration configuration classes}
92-
* to use for loading an
95+
* The {@link org.springframework.context.annotation.Configuration
96+
* configuration classes} to use for loading an
9397
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
9498
*
95-
* <p>To enable support for configuration class processing, an appropriate
96-
* {@link SmartContextLoader} must be {@link #loader configured}.
97-
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader
98-
* AnnotationConfigContextLoader} is one such loader provided by the Spring Framework.
99-
*
100-
* <p>Check out the javadoc for
101-
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#generateDefaultConfigurationClasses
102-
* AnnotationConfigContextLoader.generateDefaultConfigurationClasses()}
103-
* for details on the default configuration classes that will be used if none
104-
* are specified.
99+
* <p>Check out the Javadoc for
100+
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#detectDefaultConfigurationClasses
101+
* AnnotationConfigContextLoader.detectDefaultConfigurationClasses()} for details
102+
* on how default configuration classes will be detected if none are specified.
103+
* See the documentation for {@link #loader} for further details regarding
104+
* default loaders.
105105
*
106106
* <p>This attribute may <strong>not</strong> be used in conjunction with
107107
* {@link #locations} or {@link #value}.

org.springframework.test/src/main/java/org/springframework/test/context/ContextLoader.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import org.springframework.context.ApplicationContext;
2020

2121
/**
22-
* Strategy interface for loading an {@link ApplicationContext application context}.
22+
* Strategy interface for loading an {@link ApplicationContext application context}
23+
* for an integration test managed by the Spring TestContext Framework.
2324
*
24-
* <p><b>Note</b>: as of Spring 3.1, consider implementing {@link SmartContextLoader}
25-
* instead of this interface in order to provide support for configuration classes
26-
* and active bean definition profiles.
25+
* <p><b>Note</b>: as of Spring 3.1, implement {@link SmartContextLoader} instead
26+
* of this interface in order to provide support for configuration classes and
27+
* active bean definition profiles.
2728
*
2829
* <p>Clients of a ContextLoader should call
2930
* {@link #processLocations(Class,String...) processLocations()} prior to
@@ -38,14 +39,14 @@
3839
* <p>Spring provides the following out-of-the-box implementations:
3940
* <ul>
4041
* <li>{@link org.springframework.test.context.support.GenericXmlContextLoader GenericXmlContextLoader}</li>
41-
* <li>{@link org.springframework.test.context.support.AnnotationConfigContextLoader AnnotationConfigContextLoader}</li>
4242
* <li>{@link org.springframework.test.context.support.GenericPropertiesContextLoader GenericPropertiesContextLoader}</li>
4343
* </ul>
4444
*
4545
* @author Sam Brannen
4646
* @author Juergen Hoeller
4747
* @since 2.5
4848
* @see SmartContextLoader
49+
* @see org.springframework.test.context.support.AnnotationConfigContextLoader AnnotationConfigContextLoader
4950
*/
5051
public interface ContextLoader {
5152

@@ -68,12 +69,12 @@ public interface ContextLoader {
6869
* <p>Configuration locations are generally considered to be classpath
6970
* resources by default.
7071
* <p>Concrete implementations should register annotation configuration
71-
* processors with bean factories of
72-
* {@link ApplicationContext application contexts} loaded by this
73-
* ContextLoader. Beans will therefore automatically be candidates for
74-
* annotation-based dependency injection using
75-
* {@link org.springframework.beans.factory.annotation.Autowired @Autowired}
76-
* and {@link javax.annotation.Resource @Resource}.
72+
* processors with bean factories of {@link ApplicationContext application
73+
* contexts} loaded by this ContextLoader. Beans will therefore automatically
74+
* be candidates for annotation-based dependency injection using
75+
* {@link org.springframework.beans.factory.annotation.Autowired @Autowired},
76+
* {@link javax.annotation.Resource @Resource}, and
77+
* {@link javax.inject.Inject @Inject}.
7778
* <p>Any ApplicationContext loaded by a ContextLoader <strong>must</strong>
7879
* register a JVM shutdown hook for itself. Unless the context gets closed
7980
* early, all context instances will be automatically closed on JVM

org.springframework.test/src/main/java/org/springframework/test/context/SmartContextLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.springframework.context.ApplicationContext;
2020

2121
/**
22-
* <p>Strategy interface for loading an {@link ApplicationContext application context}
22+
* Strategy interface for loading an {@link ApplicationContext application context}
2323
* for an integration test managed by the Spring TestContext Framework.
2424
*
2525
* <p>The {@code SmartContextLoader} SPI supersedes the {@link ContextLoader} SPI
@@ -34,8 +34,9 @@
3434
* processContextConfiguration()} prior to calling
3535
* {@link #loadContext(MergedContextConfiguration) loadContext()}. This gives a
3636
* {@code SmartContextLoader} the opportunity to provide custom support for
37-
* modifying or generating resource locations or configuration classes. The
38-
* results of {@link #processContextConfiguration(ContextConfigurationAttributes)
37+
* modifying resource locations or detecting default resource locations or
38+
* default configuration classes. The results of
39+
* {@link #processContextConfiguration(ContextConfigurationAttributes)
3940
* processContextConfiguration()} should be merged for all classes in the
4041
* hierarchy of the root test class and then supplied to
4142
* {@link #loadContext(MergedContextConfiguration) loadContext()}.

org.springframework.test/src/main/java/org/springframework/test/context/TestContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public class TestContext extends AttributeAccessorSupport {
108108

109109
/**
110110
* Load an <code>ApplicationContext</code> for this test context using the
111-
* configured {@code ContextLoader} and configuration attributes.
111+
* configured {@code ContextLoader} and merged context configuration. Supports
112+
* both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
112113
* @throws Exception if an error occurs while loading the application context
113114
*/
114115
private ApplicationContext loadApplicationContext() throws Exception {

org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.util.StringUtils;
3232

3333
/**
34-
* Abstract application context loader, which provides a basis for all concrete
34+
* Abstract application context loader that provides a basis for all concrete
3535
* implementations of the {@link ContextLoader} SPI. Provides a
3636
* <em>Template Method</em> based approach for {@link #processLocations processing}
3737
* resource locations.
@@ -190,6 +190,13 @@ else if (!ResourcePatternUtils.isUrl(path)) {
190190
* Determine whether or not <em>default</em> resource locations should be
191191
* generated if the <code>locations</code> provided to
192192
* {@link #processLocations()} are <code>null</code> or empty.
193+
* <p>As of Spring 3.1, the semantics of this method have been overloaded
194+
* to include detection of either default resource locations or default
195+
* configuration classes. Consequently, this method can also be used to
196+
* determine whether or not <em>default</em> configuration classes should be
197+
* detected if the <code>classes</code> present in the
198+
* {@link ContextConfigurationAttributes configuration attributes} supplied
199+
* to {@link #processContextConfiguration()} are <code>null</code> or empty.
193200
* <p>Can be overridden by subclasses to change the default behavior.
194201
* @return always <code>true</code> by default
195202
* @since 2.5

org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
6868
* <li>Sets the <em>active bean definition profiles</em> from the supplied
6969
* <code>MergedContextConfiguration</code> in the
7070
* {@link org.springframework.core.env.Environment Environment} of the context.</li>
71-
* <li>Calls {@link #prepareContext(GenericApplicationContext)} to
72-
* prepare the context.</li>
73-
* <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to
74-
* allow for customizing the context's <code>DefaultListableBeanFactory</code>.</li>
71+
* <li>Calls {@link #prepareContext()} to allow for customizing the context
72+
* before bean definitions are loaded.</li>
73+
* <li>Calls {@link #customizeBeanFactory()} to allow for customizing the
74+
* context's <code>DefaultListableBeanFactory</code>.</li>
7575
* <li>Delegates to {@link #loadBeanDefinitions()} to populate the context
7676
* from the configuration locations or classes in the supplied
7777
* <code>MergedContextConfiguration</code>.</li>
7878
* <li>Delegates to {@link AnnotationConfigUtils} for
7979
* {@link AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
8080
* annotation configuration processors.</li>
81-
* <li>Calls {@link #customizeContext(GenericApplicationContext)} to allow
82-
* for customizing the context before it is refreshed.</li>
81+
* <li>Calls {@link #customizeContext()} to allow for customizing the context
82+
* before it is refreshed.</li>
8383
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
8484
* context and registers a JVM shutdown hook for it.</li>
8585
* </ul>
@@ -110,18 +110,18 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
110110
* <p>Implementation details:
111111
* <ul>
112112
* <li>Creates a {@link GenericApplicationContext} instance.</li>
113-
* <li>Calls {@link #prepareContext(GenericApplicationContext)} to
114-
* prepare the context.</li>
115-
* <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to
116-
* allow for customizing the context's <code>DefaultListableBeanFactory</code>.</li>
113+
* <li>Calls {@link #prepareContext()} to allow for customizing the context
114+
* before bean definitions are loaded.</li>
115+
* <li>Calls {@link #customizeBeanFactory()} to allow for customizing the
116+
* context's <code>DefaultListableBeanFactory</code>.</li>
117117
* <li>Delegates to {@link #createBeanDefinitionReader()} to create a
118118
* {@link BeanDefinitionReader} which is then used to populate the context
119119
* from the specified config locations.</li>
120120
* <li>Delegates to {@link AnnotationConfigUtils} for
121121
* {@link AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
122122
* annotation configuration processors.</li>
123-
* <li>Calls {@link #customizeContext(GenericApplicationContext)} to allow
124-
* for customizing the context before it is refreshed.</li>
123+
* <li>Calls {@link #customizeContext()} to allow for customizing the context
124+
* before it is refreshed.</li>
125125
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
126126
* context and registers a JVM shutdown hook for it.</li>
127127
* </ul>

org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @author Sam Brannen
5252
* @since 3.1
5353
* @see #processContextConfiguration()
54-
* @see #generateDefaultConfigurationClasses()
54+
* @see #detectDefaultConfigurationClasses()
5555
* @see #loadBeanDefinitions()
5656
*/
5757
public class AnnotationConfigContextLoader extends AbstractGenericContextLoader {
@@ -65,18 +65,20 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
6565
* Process configuration classes in the supplied {@link ContextConfigurationAttributes}.
6666
* <p>If the configuration classes are <code>null</code> or empty and
6767
* {@link #isGenerateDefaultLocations()} returns <code>true</code>, this
68-
* <code>SmartContextLoader</code> will attempt to
69-
* {@link #generateDefaultConfigurationClasses generate default configuration classes}.
70-
* Otherwise, properties in the supplied configuration attributes will not
71-
* be modified.
68+
* <code>SmartContextLoader</code> will attempt to {@link
69+
* #detectDefaultConfigurationClasses detect default configuration classes}.
70+
* If defaults are detected they will be
71+
* {@link ContextConfigurationAttributes#setClasses(Class[]) set} in the
72+
* supplied configuration attributes. Otherwise, properties in the supplied
73+
* configuration attributes will not be modified.
7274
* @param configAttributes the context configuration attributes to process
7375
* @see org.springframework.test.context.SmartContextLoader#processContextConfiguration()
7476
* @see #isGenerateDefaultLocations()
75-
* @see #generateDefaultConfigurationClasses()
77+
* @see #detectDefaultConfigurationClasses()
7678
*/
7779
public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
7880
if (ObjectUtils.isEmpty(configAttributes.getClasses()) && isGenerateDefaultLocations()) {
79-
Class<?>[] defaultConfigClasses = generateDefaultConfigurationClasses(configAttributes.getDeclaringClass());
81+
Class<?>[] defaultConfigClasses = detectDefaultConfigurationClasses(configAttributes.getDeclaringClass());
8082
configAttributes.setClasses(defaultConfigClasses);
8183
}
8284
}
@@ -108,24 +110,23 @@ private boolean isDefaultConfigurationClassCandidate(Class<?> clazz) {
108110
}
109111

110112
/**
111-
* Generate the default configuration class array for the supplied test class.
112-
* <p>The generated class array will contain all static inner classes of
113+
* Detect the default configuration classes for the supplied test class.
114+
* <p>The returned class array will contain all static inner classes of
113115
* the supplied class that meet the requirements for {@code @Configuration}
114116
* class implementations as specified in the documentation for
115117
* {@link Configuration @Configuration}.
116118
* <p>The implementation of this method adheres to the contract defined in the
117119
* {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}
118-
* SPI. Specifically, this method will <em>preemptively</em> verify that the
119-
* generated default configuration classes exist <b>and</b> that such classes
120-
* comply with the constraints required of {@code @Configuration} class
121-
* implementations. If a candidate configuration class does meet these
122-
* requirements, this method will log a warning, and the candidate class will
123-
* be ignored.
120+
* SPI. Specifically, this method uses introspection to detect default
121+
* configuration classes that comply with the constraints required of
122+
* {@code @Configuration} class implementations. If a potential candidate
123+
* configuration class does meet these requirements, this method will log a
124+
* warning, and the potential candidate class will be ignored.
124125
* @param declaringClass the test class that declared {@code @ContextConfiguration}
125126
* @return an array of default configuration classes, potentially empty but
126127
* never <code>null</code>
127128
*/
128-
protected Class<?>[] generateDefaultConfigurationClasses(Class<?> declaringClass) {
129+
protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass) {
129130
Assert.notNull(declaringClass, "Declaring class must not be null");
130131

131132
List<Class<?>> configClasses = new ArrayList<Class<?>>();

0 commit comments

Comments
 (0)