Skip to content

Commit 479ef3f

Browse files
committed
Update documentation regarding nested test class support
Closes gh-28579
1 parent be1b7da commit 479ef3f

23 files changed

+176
-127
lines changed

spring-test/src/main/java/org/springframework/test/annotation/Commit.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -34,8 +34,8 @@
3434
*
3535
* <p>When declared as a class-level annotation, {@code @Commit} defines
3636
* the default commit semantics for all test methods within the test class
37-
* hierarchy. When declared as a method-level annotation, {@code @Commit}
38-
* defines commit semantics for the specific test method, potentially
37+
* hierarchy or nested class hierarchy. When declared as a method-level annotation,
38+
* {@code @Commit} defines commit semantics for the specific test method, potentially
3939
* overriding class-level default commit or rollback semantics.
4040
*
4141
* <p><strong>Warning</strong>: {@code @Commit} can be used as direct

spring-test/src/main/java/org/springframework/test/annotation/Rollback.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -34,9 +34,9 @@
3434
*
3535
* <p>When declared as a class-level annotation, {@code @Rollback} defines
3636
* the default rollback semantics for all test methods within the test class
37-
* hierarchy. When declared as a method-level annotation, {@code @Rollback}
38-
* defines rollback semantics for the specific test method, potentially
39-
* overriding class-level default commit or rollback semantics.
37+
* hierarchy or nested class hierarchy. When declared as a method-level annotation,
38+
* {@code @Rollback} defines rollback semantics for the specific test method,
39+
* potentially overriding class-level default commit or rollback semantics.
4040
*
4141
* <p>As of Spring Framework 4.2, {@code @Commit} can be used as direct
4242
* replacement for {@code @Rollback(false)}.

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -78,17 +78,17 @@
7878
Class<? extends ActiveProfilesResolver> resolver() default ActiveProfilesResolver.class;
7979

8080
/**
81-
* Whether or not bean definition profiles from superclasses should be
82-
* <em>inherited</em>.
83-
* <p>The default value is {@code true}, which means that a test
84-
* class will <em>inherit</em> bean definition profiles defined by a
85-
* test superclass. Specifically, the bean definition profiles for a test
86-
* class will be appended to the list of bean definition profiles
87-
* defined by a test superclass. Thus, subclasses have the option of
88-
* <em>extending</em> the list of bean definition profiles.
89-
* <p>If {@code inheritProfiles} is set to {@code false}, the bean
90-
* definition profiles for the test class will <em>shadow</em> and
91-
* effectively replace any bean definition profiles defined by a superclass.
81+
* Whether or not bean definition profiles from superclasses and enclosing
82+
* classes should be <em>inherited</em>.
83+
* <p>The default value is {@code true}, which means that a test class will
84+
* <em>inherit</em> bean definition profiles defined by a test superclass or
85+
* enclosing class. Specifically, the bean definition profiles for a test
86+
* class will be appended to the list of bean definition profiles defined by
87+
* a test superclass or enclosing class. Thus, subclasses and nested classes
88+
* have the option of <em>extending</em> the list of bean definition profiles.
89+
* <p>If {@code inheritProfiles} is set to {@code false}, the bean definition
90+
* profiles for the test class will <em>shadow</em> and effectively replace
91+
* any bean definition profiles defined by a superclass or enclosing class.
9292
* <p>In the following example, the {@code ApplicationContext} for
9393
* {@code BaseTest} will be loaded using only the &quot;base&quot;
9494
* bean definition profile; beans defined in the &quot;extended&quot; profile

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -171,18 +171,19 @@
171171
/**
172172
* Whether or not {@linkplain #locations resource locations} or
173173
* {@linkplain #classes <em>component classes</em>} from test superclasses
174-
* should be <em>inherited</em>.
174+
* and enclosing classes should be <em>inherited</em>.
175175
* <p>The default value is {@code true}. This means that an annotated test
176176
* class will <em>inherit</em> the resource locations or component classes
177-
* defined by test superclasses. Specifically, the resource locations or
178-
* component classes for a given test class will be appended to the list of
179-
* resource locations or component classes defined by test superclasses.
180-
* Thus, subclasses have the option of <em>extending</em> the list of resource
177+
* defined by test superclasses and enclosing classes. Specifically, the
178+
* resource locations or component classes for a given test class will be
179+
* appended to the list of resource locations or component classes defined
180+
* by test superclasses and enclosing classes. Thus, subclasses and nested
181+
* classes have the option of <em>extending</em> the list of resource
181182
* locations or component classes.
182183
* <p>If {@code inheritLocations} is set to {@code false}, the
183184
* resource locations or component classes for the annotated test class
184185
* will <em>shadow</em> and effectively replace any resource locations
185-
* or component classes defined by superclasses.
186+
* or component classes defined by superclasses and enclosing classes.
186187
* <p>In the following example that uses path-based resource locations, the
187188
* {@link org.springframework.context.ApplicationContext ApplicationContext}
188189
* for {@code ExtendedTest} will be loaded from
@@ -225,16 +226,16 @@
225226

226227
/**
227228
* Whether or not {@linkplain #initializers context initializers} from test
228-
* superclasses should be <em>inherited</em>.
229+
* superclasses and enclosing classes should be <em>inherited</em>.
229230
* <p>The default value is {@code true}. This means that an annotated test
230231
* class will <em>inherit</em> the application context initializers defined
231-
* by test superclasses. Specifically, the initializers for a given test
232-
* class will be added to the set of initializers defined by test
233-
* superclasses. Thus, subclasses have the option of <em>extending</em> the
234-
* set of initializers.
232+
* by test superclasses and enclosing classes. Specifically, the initializers
233+
* for a given test class will be added to the set of initializers defined by
234+
* test superclasses and enclosing classes. Thus, subclasses and nested classes
235+
* have the option of <em>extending</em> the set of initializers.
235236
* <p>If {@code inheritInitializers} is set to {@code false}, the initializers
236237
* for the annotated test class will <em>shadow</em> and effectively replace
237-
* any initializers defined by superclasses.
238+
* any initializers defined by superclasses and enclosing classes.
238239
* <p>In the following example, the
239240
* {@link org.springframework.context.ApplicationContext ApplicationContext}
240241
* for {@code ExtendedTest} will be initialized using
@@ -263,9 +264,10 @@
263264
* for loading an {@link org.springframework.context.ApplicationContext
264265
* ApplicationContext}.
265266
* <p>If not specified, the loader will be inherited from the first superclass
266-
* that is annotated or meta-annotated with {@code @ContextConfiguration} and
267-
* specifies an explicit loader. If no class in the hierarchy specifies an
268-
* explicit loader, a default loader will be used instead.
267+
* or enclosing class that is annotated or meta-annotated with
268+
* {@code @ContextConfiguration} and specifies an explicit loader. If no class
269+
* in the type hierarchy or enclosing class hierarchy specifies an explicit
270+
* loader, a default loader will be used instead.
269271
* <p>The default concrete implementation chosen at runtime will be either
270272
* {@link org.springframework.test.context.support.DelegatingSmartContextLoader
271273
* DelegatingSmartContextLoader} or
@@ -290,10 +292,12 @@
290292
* <p>If not specified the name will be inferred based on the numerical level
291293
* within all declared contexts within the hierarchy.
292294
* <p>This attribute is only applicable when used within a test class hierarchy
293-
* that is configured using {@code @ContextHierarchy}, in which case the name
294-
* can be used for <em>merging</em> or <em>overriding</em> this configuration
295-
* with configuration of the same name in hierarchy levels defined in superclasses.
296-
* See the Javadoc for {@link ContextHierarchy @ContextHierarchy} for details.
295+
* or enclosing class hierarchy that is configured using
296+
* {@code @ContextHierarchy}, in which case the name can be used for
297+
* <em>merging</em> or <em>overriding</em> this configuration with configuration
298+
* of the same name in hierarchy levels defined in superclasses or enclosing
299+
* classes. See the Javadoc for {@link ContextHierarchy @ContextHierarchy} for
300+
* details.
297301
* @since 3.2.2
298302
*/
299303
String name() default "";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -46,7 +46,7 @@ public interface ContextCustomizerFactory {
4646
* @param testClass the test class
4747
* @param configAttributes the list of context configuration attributes for
4848
* the test class, ordered <em>bottom-up</em> (i.e., as if we were traversing
49-
* up the class hierarchy); never {@code null} or empty
49+
* up the class hierarchy or enclosing class hierarchy); never {@code null} or empty
5050
* @return a {@link ContextCustomizer} or {@code null} if no customizer should
5151
* be used
5252
*/

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -31,16 +31,16 @@
3131
import org.springframework.util.StringUtils;
3232

3333
/**
34-
* {@code MergedContextConfiguration} encapsulates the <em>merged</em>
35-
* context configuration declared on a test class and all of its superclasses
36-
* via {@link ContextConfiguration @ContextConfiguration},
34+
* {@code MergedContextConfiguration} encapsulates the <em>merged</em> context
35+
* configuration declared on a test class and all of its superclasses and
36+
* enclosing classes via {@link ContextConfiguration @ContextConfiguration},
3737
* {@link ActiveProfiles @ActiveProfiles}, and
3838
* {@link TestPropertySource @TestPropertySource}.
3939
*
4040
* <p>Merged context resource locations, annotated classes, active profiles,
4141
* property resource locations, and in-lined properties represent all declared
42-
* values in the test class hierarchy taking into consideration the semantics
43-
* of the {@link ContextConfiguration#inheritLocations},
42+
* values in the test class hierarchy and enclosing class hierarchy taking into
43+
* consideration the semantics of the {@link ContextConfiguration#inheritLocations},
4444
* {@link ActiveProfiles#inheritProfiles},
4545
* {@link TestPropertySource#inheritLocations}, and
4646
* {@link TestPropertySource#inheritProperties} flags.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -126,7 +126,8 @@ public interface TestContextBootstrapper {
126126
* flag of {@link TestExecutionListeners @TestExecutionListeners} must be
127127
* taken into consideration. Specifically, if the {@code inheritListeners}
128128
* flag is set to {@code true}, listeners declared for a given test class must
129-
* be appended to the end of the list of listeners declared in superclasses.
129+
* be appended to the end of the list of listeners declared in superclasses
130+
* or enclosing classes.
130131
* @return a list of {@code TestExecutionListener} instances
131132
*/
132133
List<TestExecutionListener> getTestExecutionListeners();

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -79,15 +79,16 @@
7979

8080
/**
8181
* Whether or not {@link #listeners TestExecutionListeners} from superclasses
82-
* should be <em>inherited</em>.
83-
* <p>The default value is {@code true}, which means that an annotated
84-
* class will <em>inherit</em> the listeners defined by an annotated
85-
* superclass. Specifically, the listeners for an annotated class will be
86-
* appended to the list of listeners defined by an annotated superclass.
87-
* Thus, subclasses have the option of <em>extending</em> the list of
88-
* listeners. In the following example, {@code AbstractBaseTest} will
89-
* be configured with {@code DependencyInjectionTestExecutionListener}
90-
* and {@code DirtiesContextTestExecutionListener}; whereas,
82+
* and enclosing classes should be <em>inherited</em>.
83+
* <p>The default value is {@code true}, which means that an annotated class
84+
* will <em>inherit</em> the listeners defined by an annotated superclass or
85+
* enclosing class. Specifically, the listeners for an annotated class will be
86+
* appended to the list of listeners defined by an annotated superclass or
87+
* enclosing class. Thus, subclasses and nested classes have the option of
88+
* <em>extending</em> the list of listeners. In the following example,
89+
* {@code AbstractBaseTest} will be configured with
90+
* {@code DependencyInjectionTestExecutionListener} and
91+
* {@code DirtiesContextTestExecutionListener}; whereas,
9192
* {@code TransactionalTest} will be configured with
9293
* {@code DependencyInjectionTestExecutionListener},
9394
* {@code DirtiesContextTestExecutionListener}, <strong>and</strong>
@@ -107,18 +108,19 @@
107108
* }</pre>
108109
* <p>If {@code inheritListeners} is set to {@code false}, the listeners for
109110
* the annotated class will <em>shadow</em> and effectively replace any
110-
* listeners defined by a superclass.
111+
* listeners defined by a superclass or enclosing class.
111112
*/
112113
boolean inheritListeners() default true;
113114

114115
/**
115116
* The <em>merge mode</em> to use when {@code @TestExecutionListeners} is
116-
* declared on a class that does <strong>not</strong> inherit listeners
117-
* from a superclass.
117+
* declared on a class that does <strong>not</strong> inherit listeners from
118+
* a superclass or enclosing class.
118119
* <p>Can be set to {@link MergeMode#MERGE_WITH_DEFAULTS MERGE_WITH_DEFAULTS}
119120
* to have locally declared listeners <em>merged</em> with the default
120121
* listeners.
121-
* <p>The mode is ignored if listeners are inherited from a superclass.
122+
* <p>The mode is ignored if listeners are inherited from a superclass or
123+
* enclosing class.
122124
* <p>Defaults to {@link MergeMode#REPLACE_DEFAULTS REPLACE_DEFAULTS}
123125
* for backwards compatibility.
124126
* @see MergeMode
@@ -131,7 +133,8 @@
131133
* Enumeration of <em>modes</em> that dictate whether or not explicitly
132134
* declared listeners are merged with the default listeners when
133135
* {@code @TestExecutionListeners} is declared on a class that does
134-
* <strong>not</strong> inherit listeners from a superclass.
136+
* <strong>not</strong> inherit listeners from a superclass or enclosing
137+
* class.
135138
* @since 4.1
136139
*/
137140
enum MergeMode {

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -151,16 +151,18 @@
151151

152152
/**
153153
* Whether or not test property source {@link #locations} from superclasses
154-
* should be <em>inherited</em>.
154+
* and enclosing classes should be <em>inherited</em>.
155155
* <p>The default value is {@code true}, which means that a test class will
156-
* <em>inherit</em> property source locations defined by a superclass.
157-
* Specifically, the property source locations for a test class will be
158-
* appended to the list of property source locations defined by a superclass.
159-
* Thus, subclasses have the option of <em>extending</em> the list of test
160-
* property source locations.
156+
* <em>inherit</em> property source locations defined by a superclass or
157+
* enclosing class. Specifically, the property source locations for a test
158+
* class will be appended to the list of property source locations defined
159+
* by a superclass or enclosing class. Thus, subclasses and nested classes
160+
* have the option of <em>extending</em> the list of test property source
161+
* locations.
161162
* <p>If {@code inheritLocations} is set to {@code false}, the property
162163
* source locations for the test class will <em>shadow</em> and effectively
163-
* replace any property source locations defined by a superclass.
164+
* replace any property source locations defined by a superclass or
165+
* enclosing class.
164166
* <p>In the following example, the {@code ApplicationContext} for
165167
* {@code BaseTest} will be loaded using only the {@code "base.properties"}
166168
* file as a test property source. In contrast, the {@code ApplicationContext}
@@ -228,16 +230,17 @@
228230
String[] properties() default {};
229231

230232
/**
231-
* Whether or not inlined test {@link #properties} from superclasses should
232-
* be <em>inherited</em>.
233+
* Whether or not inlined test {@link #properties} from superclasses and
234+
* enclosing classes should be <em>inherited</em>.
233235
* <p>The default value is {@code true}, which means that a test class will
234-
* <em>inherit</em> inlined properties defined by a superclass. Specifically,
235-
* the inlined properties for a test class will be appended to the list of
236-
* inlined properties defined by a superclass. Thus, subclasses have the
237-
* option of <em>extending</em> the list of inlined test properties.
236+
* <em>inherit</em> inlined properties defined by a superclass or enclosing
237+
* class. Specifically, the inlined properties for a test class will be
238+
* appended to the list of inlined properties defined by a superclass or
239+
* enclosing class. Thus, subclasses and nested classes have the option of
240+
* <em>extending</em> the list of inlined test properties.
238241
* <p>If {@code inheritProperties} is set to {@code false}, the inlined
239242
* properties for the test class will <em>shadow</em> and effectively
240-
* replace any inlined properties defined by a superclass.
243+
* replace any inlined properties defined by a superclass or enclosing class.
241244
* <p>In the following example, the {@code ApplicationContext} for
242245
* {@code BaseTest} will be loaded using only the inlined {@code key1}
243246
* property. In contrast, the {@code ApplicationContext} for
@@ -261,7 +264,7 @@
261264
* test class hierarchy (i.e., directly present or meta-present on a test
262265
* class) are considered to be <em>local</em> annotations, in contrast to
263266
* {@code @TestPropertySource} annotations that are inherited from a
264-
* superclass.</li>
267+
* superclass or enclosing class.</li>
265268
* <li>All local {@code @TestPropertySource} annotations must declare the
266269
* same value for the {@code inheritProperties} flag.</li>
267270
* <li>The {@code inheritProperties} flag is not taken into account between

spring-test/src/main/java/org/springframework/test/context/event/RecordApplicationEvents.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -36,6 +36,10 @@
3636
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
3737
* <em>composed annotations</em>.
3838
*
39+
* <p>This annotation will be inherited from an enclosing test class by default. See
40+
* {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
41+
* for details.
42+
*
3943
* @author Sam Brannen
4044
* @since 5.3.3
4145
* @see ApplicationEvents

0 commit comments

Comments
 (0)