Skip to content

Commit 36e7cb2

Browse files
committed
Improve documentation of annotated class support in the TCF
Updated all Javadoc in the Spring TestContext Framework (TCF) to explain and refer to 'annotated classes' instead of 'configuration classes'. Specifically, @ContextConfiguration now explicitly defines what is meant by 'annotated classes', and various other classes now refer to this definition. Otherwise, the term 'configuration class' has simply been replaced with 'annotated class'. Also deleted cross references to deprecated JUnit 3.8 classes and formatted Javadoc in general for greater readability. Issue: SPR-9401
1 parent 59e3223 commit 36e7cb2

19 files changed

+227
-133
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
21
/**
3-
*
42
* Support classes for annotation-driven tests.
5-
*
63
*/
4+
75
package org.springframework.test.annotation;
86

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,15 +65,15 @@
6565
* Whether or not bean definition profiles from superclasses should be
6666
* <em>inherited</em>.
6767
*
68-
* <p>The default value is <code>true</code>, which means that an annotated
69-
* class will <em>inherit</em> bean definition profiles defined by an
70-
* annotated superclass. Specifically, the bean definition profiles for an
71-
* annotated class will be appended to the list of bean definition profiles
72-
* defined by an annotated superclass. Thus, subclasses have the option of
68+
* <p>The default value is <code>true</code>, which means that a test
69+
* class will <em>inherit</em> bean definition profiles defined by a
70+
* test superclass. Specifically, the bean definition profiles for a test
71+
* class will be appended to the list of bean definition profiles
72+
* defined by a test superclass. Thus, subclasses have the option of
7373
* <em>extending</em> the list of bean definition profiles.
7474
*
7575
* <p>If <code>inheritProfiles</code> is set to <code>false</code>, the bean
76-
* definition profiles for the annotated class will <em>shadow</em> and
76+
* definition profiles for the test class will <em>shadow</em> and
7777
* effectively replace any bean definition profiles defined by a superclass.
7878
*
7979
* <p>In the following example, the {@code ApplicationContext} for
@@ -98,7 +98,8 @@
9898
*
9999
* <p>Note: {@code @ActiveProfiles} can be used when loading an
100100
* {@code ApplicationContext} from path-based resource locations or
101-
* configuration classes.
101+
* annotated classes.
102+
*
102103
* @see ContextConfiguration#locations
103104
* @see ContextConfiguration#classes
104105
* @see ContextConfiguration#inheritLocations

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,16 +25,15 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* Cache for Spring {@link ApplicationContext ApplicationContexts}
29-
* in a test environment.
28+
* Cache for Spring {@link ApplicationContext ApplicationContexts} in a test environment.
3029
*
3130
* <p>Maintains a cache of {@link ApplicationContext contexts} keyed by
3231
* {@link MergedContextConfiguration} instances. This has significant performance
3332
* benefits if initializing the context would take time. While initializing a
3433
* Spring context itself is very quick, some beans in a context, such as a
35-
* {@link org.springframework.orm.hibernate3.LocalSessionFactoryBean LocalSessionFactoryBean}
36-
* for working with Hibernate, may take some time to initialize. Hence it often
37-
* makes sense to perform that initialization once.
34+
* {@code LocalSessionFactoryBean} for working with Hibernate, may take some time
35+
* to initialize. Hence it often makes sense to perform that initialization only
36+
* once per test suite.
3837
*
3938
* @author Sam Brannen
4039
* @author Juergen Hoeller
@@ -70,6 +69,7 @@ void clearStatistics() {
7069

7170
/**
7271
* Return whether there is a cached context for the given key.
72+
*
7373
* @param key the context key (never <code>null</code>)
7474
*/
7575
boolean contains(MergedContextConfiguration key) {
@@ -79,8 +79,10 @@ boolean contains(MergedContextConfiguration key) {
7979

8080
/**
8181
* Obtain a cached ApplicationContext for the given key.
82+
*
8283
* <p>The {@link #getHitCount() hit} and {@link #getMissCount() miss}
8384
* counts will be updated accordingly.
85+
*
8486
* @param key the context key (never <code>null</code>)
8587
* @return the corresponding ApplicationContext instance,
8688
* or <code>null</code> if not found in the cache.
@@ -133,6 +135,7 @@ int getMissCount() {
133135

134136
/**
135137
* Explicitly add an ApplicationContext instance to the cache under the given key.
138+
*
136139
* @param key the context key (never <code>null</code>)
137140
* @param context the ApplicationContext instance (never <code>null</code>)
138141
*/
@@ -144,9 +147,10 @@ void put(MergedContextConfiguration key, ApplicationContext context) {
144147

145148
/**
146149
* Remove the context with the given key.
150+
*
147151
* @param key the context key (never <code>null</code>)
148-
* @return the corresponding ApplicationContext instance,
149-
* or <code>null</code> if not found in the cache.
152+
* @return the corresponding ApplicationContext instance, or <code>null</code>
153+
* if not found in the cache.
150154
* @see #setDirty
151155
*/
152156
ApplicationContext remove(MergedContextConfiguration key) {
@@ -156,11 +160,13 @@ ApplicationContext remove(MergedContextConfiguration key) {
156160
/**
157161
* Mark the context with the given key as dirty, effectively
158162
* {@link #remove removing} the context from the cache and explicitly
159-
* {@link ConfigurableApplicationContext#close() closing} it if
160-
* it is an instance of {@link ConfigurableApplicationContext}.
163+
* {@link ConfigurableApplicationContext#close() closing} it if it is an
164+
* instance of {@link ConfigurableApplicationContext}.
165+
*
161166
* <p>Generally speaking, you would only call this method if you change the
162167
* state of a singleton bean, potentially affecting future interaction with
163168
* the context.
169+
*
164170
* @param key the context key (never <code>null</code>)
165171
* @see #remove
166172
*/

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

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,20 +23,43 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
28+
2629
/**
2730
* {@code ContextConfiguration} defines class-level metadata that is
2831
* used to determine how to load and configure an
2932
* {@link org.springframework.context.ApplicationContext ApplicationContext}
3033
* for test classes.
31-
*
34+
*
35+
* <h3>Supported Resource Types</h3>
36+
*
3237
* <p>Prior to Spring 3.1, only path-based resource locations were supported.
3338
* As of Spring 3.1, {@link #loader context loaders} may choose to support
3439
* either path-based or class-based resources (but not both). Consequently
3540
* {@code @ContextConfiguration} can be used to declare either path-based
3641
* resource locations (via the {@link #locations} or {@link #value}
37-
* attribute) <i>or</i> configuration classes (via the {@link #classes}
42+
* attribute) <i>or</i> annotated classes (via the {@link #classes}
3843
* attribute).
39-
*
44+
*
45+
* <h3>Annotated Classes</h3>
46+
*
47+
* <p>The term <em>annotated class</em> can refer to any of the following.
48+
*
49+
* <ul>
50+
* <li>A class annotated with {@link Configuration @Configuration}</li>
51+
* <li>A component (i.e., a class annotated with
52+
* {@link org.springframework.stereotype.Component @Component},
53+
* {@link org.springframework.stereotype.Service @Service},
54+
* {@link org.springframework.stereotype.Repository @Repository}, etc.)</li>
55+
* <li>A JSR-330 compliant class that is annotated with {@code javax.inject} annotations</li>
56+
* <li>Any other class that contains {@link Bean @Bean}-methods</li>
57+
* </ul>
58+
*
59+
* Consult the JavaDoc for {@link Configuration @Configuration} and {@link Bean @Bean}
60+
* for further information regarding the configuration and semantics of
61+
* <em>annotated classes</em>.
62+
*
4063
* @author Sam Brannen
4164
* @since 2.5
4265
* @see ContextLoader
@@ -92,43 +115,41 @@
92115
String[] locations() default {};
93116

94117
/**
95-
* The {@link org.springframework.context.annotation.Configuration
96-
* configuration classes} to use for loading an
118+
* The <em>annotated classes</em> to use for loading an
97119
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
98120
*
99121
* <p>Check out the Javadoc for
100122
* {@link org.springframework.test.context.support.AnnotationConfigContextLoader#detectDefaultConfigurationClasses
101123
* 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.
124+
* on how default configuration classes will be detected if no
125+
* <em>annotated classes</em> are specified. See the documentation for
126+
* {@link #loader} for further details regarding default loaders.
105127
*
106128
* <p>This attribute may <strong>not</strong> be used in conjunction with
107129
* {@link #locations} or {@link #value}.
130+
*
108131
* @since 3.1
109132
* @see org.springframework.context.annotation.Configuration
110133
* @see org.springframework.test.context.support.AnnotationConfigContextLoader
111134
*/
112135
Class<?>[] classes() default {};
113136

114137
/**
115-
* Whether or not {@link #locations resource locations} or
116-
* {@link #classes configuration classes} from superclasses should be
117-
* <em>inherited</em>.
118-
*
138+
* Whether or not {@link #locations resource locations} or <em>annotated
139+
* classes</em> from test superclasses should be <em>inherited</em>.
140+
*
119141
* <p>The default value is <code>true</code>. This means that an annotated
120-
* class will <em>inherit</em> the resource locations or configuration
121-
* classes defined by annotated superclasses. Specifically, the resource
122-
* locations or configuration classes for an annotated class will be
123-
* appended to the list of resource locations or configuration classes
124-
* defined by annotated superclasses. Thus, subclasses have the option of
125-
* <em>extending</em> the list of resource locations or configuration
126-
* classes.
142+
* class will <em>inherit</em> the resource locations or annotated classes
143+
* defined by test superclasses. Specifically, the resource locations or
144+
* annotated classes for a given test class will be appended to the list of
145+
* resource locations or annotated classes defined by test superclasses.
146+
* Thus, subclasses have the option of <em>extending</em> the list of resource
147+
* locations or annotated classes.
127148
*
128149
* <p>If <code>inheritLocations</code> is set to <code>false</code>, the
129-
* resource locations or configuration classes for the annotated class
150+
* resource locations or annotated classes for the annotated class
130151
* will <em>shadow</em> and effectively replace any resource locations
131-
* or configuration classes defined by superclasses.
152+
* or annotated classes defined by superclasses.
132153
*
133154
* <p>In the following example that uses path-based resource locations, the
134155
* {@link org.springframework.context.ApplicationContext ApplicationContext}
@@ -149,7 +170,7 @@
149170
* }
150171
* </pre>
151172
*
152-
* <p>Similarly, in the following example that uses configuration
173+
* <p>Similarly, in the following example that uses annotated
153174
* classes, the
154175
* {@link org.springframework.context.ApplicationContext ApplicationContext}
155176
* for {@code ExtendedTest} will be loaded from the

spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ContextConfigurationAttributes(Class<?> declaringClass, ContextConfigurat
9696
*
9797
* @param declaringClass the test class that declared {@code @ContextConfiguration}
9898
* @param locations the resource locations declared via {@code @ContextConfiguration}
99-
* @param classes the configuration classes declared via {@code @ContextConfiguration}
99+
* @param classes the annotated classes declared via {@code @ContextConfiguration}
100100
* @param inheritLocations the <code>inheritLocations</code> flag declared via {@code @ContextConfiguration}
101101
* @param contextLoaderClass the {@code ContextLoader} class declared via {@code @ContextConfiguration}
102102
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is
@@ -128,6 +128,7 @@ public ContextConfigurationAttributes(Class<?> declaringClass, String[] location
128128
/**
129129
* Get the {@link Class class} that declared the
130130
* {@link ContextConfiguration @ContextConfiguration} annotation.
131+
*
131132
* @return the declaring class; never <code>null</code>
132133
*/
133134
public Class<?> getDeclaringClass() {
@@ -137,9 +138,11 @@ public Class<?> getDeclaringClass() {
137138
/**
138139
* Get the resource locations that were declared via
139140
* {@link ContextConfiguration @ContextConfiguration}.
141+
*
140142
* <p>Note: this is a mutable property. The returned value may therefore
141143
* represent a <em>processed</em> value that does not match the original value
142144
* declared via {@link ContextConfiguration @ContextConfiguration}.
145+
*
143146
* @return the resource locations; potentially <code>null</code> or <em>empty</em>
144147
* @see ContextConfiguration#value
145148
* @see ContextConfiguration#locations
@@ -152,19 +155,22 @@ public String[] getLocations() {
152155
/**
153156
* Set the <em>processed</em> resource locations, effectively overriding the
154157
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
158+
*
155159
* @see #getLocations()
156160
*/
157161
public void setLocations(String[] locations) {
158162
this.locations = locations;
159163
}
160164

161165
/**
162-
* Get the configuration classes that were declared via
166+
* Get the annotated classes that were declared via
163167
* {@link ContextConfiguration @ContextConfiguration}.
168+
*
164169
* <p>Note: this is a mutable property. The returned value may therefore
165170
* represent a <em>processed</em> value that does not match the original value
166171
* declared via {@link ContextConfiguration @ContextConfiguration}.
167-
* @return the configuration classes; potentially <code>null</code> or <em>empty</em>
172+
*
173+
* @return the annotated classes; potentially <code>null</code> or <em>empty</em>
168174
* @see ContextConfiguration#classes
169175
* @see #setClasses(Class[])
170176
*/
@@ -173,8 +179,9 @@ public Class<?>[] getClasses() {
173179
}
174180

175181
/**
176-
* Set the <em>processed</em> configuration classes, effectively overriding the
182+
* Set the <em>processed</em> annotated classes, effectively overriding the
177183
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
184+
*
178185
* @see #getClasses()
179186
*/
180187
public void setClasses(Class<?>[] classes) {
@@ -184,6 +191,7 @@ public void setClasses(Class<?>[] classes) {
184191
/**
185192
* Determine if this {@code ContextConfigurationAttributes} instance has
186193
* path-based resource locations.
194+
*
187195
* @return <code>true</code> if the {@link #getLocations() locations} array is not empty
188196
* @see #hasResources()
189197
* @see #hasClasses()
@@ -195,6 +203,7 @@ public boolean hasLocations() {
195203
/**
196204
* Determine if this {@code ContextConfigurationAttributes} instance has
197205
* class-based resources.
206+
*
198207
* @return <code>true</code> if the {@link #getClasses() classes} array is not empty
199208
* @see #hasResources()
200209
* @see #hasLocations()
@@ -206,6 +215,7 @@ public boolean hasClasses() {
206215
/**
207216
* Determine if this {@code ContextConfigurationAttributes} instance has
208217
* either path-based resource locations or class-based resources.
218+
*
209219
* @return <code>true</code> if either the {@link #getLocations() locations}
210220
* or the {@link #getClasses() classes} array is not empty
211221
* @see #hasLocations()
@@ -218,6 +228,7 @@ public boolean hasResources() {
218228
/**
219229
* Get the <code>inheritLocations</code> flag that was declared via
220230
* {@link ContextConfiguration @ContextConfiguration}.
231+
*
221232
* @return the <code>inheritLocations</code> flag
222233
* @see ContextConfiguration#inheritLocations
223234
*/
@@ -228,6 +239,7 @@ public boolean isInheritLocations() {
228239
/**
229240
* Get the <code>ContextLoader</code> class that was declared via
230241
* {@link ContextConfiguration @ContextConfiguration}.
242+
*
231243
* @return the <code>ContextLoader</code> class
232244
* @see ContextConfiguration#loader
233245
*/

0 commit comments

Comments
 (0)