diff --git a/spring-test/src/main/java/org/springframework/test/annotation/Commit.java b/spring-test/src/main/java/org/springframework/test/annotation/Commit.java index 9e881a5de4..c4cb54cbfa 100644 --- a/spring-test/src/main/java/org/springframework/test/annotation/Commit.java +++ b/spring-test/src/main/java/org/springframework/test/annotation/Commit.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,8 @@ import java.lang.annotation.Target; * *
When declared as a class-level annotation, {@code @Commit} defines * the default commit semantics for all test methods within the test class - * hierarchy. When declared as a method-level annotation, {@code @Commit} - * defines commit semantics for the specific test method, potentially + * hierarchy or nested class hierarchy. When declared as a method-level annotation, + * {@code @Commit} defines commit semantics for the specific test method, potentially * overriding class-level default commit or rollback semantics. * *
Warning: {@code @Commit} can be used as direct diff --git a/spring-test/src/main/java/org/springframework/test/annotation/Rollback.java b/spring-test/src/main/java/org/springframework/test/annotation/Rollback.java index a7bd5c0641..33b0298722 100644 --- a/spring-test/src/main/java/org/springframework/test/annotation/Rollback.java +++ b/spring-test/src/main/java/org/springframework/test/annotation/Rollback.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ import java.lang.annotation.Target; * *
When declared as a class-level annotation, {@code @Rollback} defines * the default rollback semantics for all test methods within the test class - * hierarchy. When declared as a method-level annotation, {@code @Rollback} - * defines rollback semantics for the specific test method, potentially - * overriding class-level default commit or rollback semantics. + * hierarchy or nested class hierarchy. When declared as a method-level annotation, + * {@code @Rollback} defines rollback semantics for the specific test method, + * potentially overriding class-level default commit or rollback semantics. * *
As of Spring Framework 4.2, {@code @Commit} can be used as direct * replacement for {@code @Rollback(false)}. diff --git a/spring-test/src/main/java/org/springframework/test/context/ActiveProfiles.java b/spring-test/src/main/java/org/springframework/test/context/ActiveProfiles.java index b9b8ddfd64..343ba5b985 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ActiveProfiles.java +++ b/spring-test/src/main/java/org/springframework/test/context/ActiveProfiles.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,17 +78,17 @@ public @interface ActiveProfiles { Class extends ActiveProfilesResolver> resolver() default ActiveProfilesResolver.class; /** - * Whether or not bean definition profiles from superclasses should be - * inherited. - *
The default value is {@code true}, which means that a test - * class will inherit bean definition profiles defined by a - * test superclass. Specifically, the bean definition profiles for a test - * class will be appended to the list of bean definition profiles - * defined by a test superclass. Thus, subclasses have the option of - * extending the list of bean definition profiles. - *
If {@code inheritProfiles} is set to {@code false}, the bean - * definition profiles for the test class will shadow and - * effectively replace any bean definition profiles defined by a superclass. + * Whether or not bean definition profiles from superclasses and enclosing + * classes should be inherited. + *
The default value is {@code true}, which means that a test class will + * inherit bean definition profiles defined by a test superclass or + * enclosing class. Specifically, the bean definition profiles for a test + * class will be appended to the list of bean definition profiles defined by + * a test superclass or enclosing class. Thus, subclasses and nested classes + * have the option of extending the list of bean definition profiles. + *
If {@code inheritProfiles} is set to {@code false}, the bean definition + * profiles for the test class will shadow and effectively replace + * any bean definition profiles defined by a superclass or enclosing class. *
In the following example, the {@code ApplicationContext} for * {@code BaseTest} will be loaded using only the "base" * bean definition profile; beans defined in the "extended" profile diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/ContextConfiguration.java index 9eaabcb4f0..23c2def0fa 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,18 +171,19 @@ public @interface ContextConfiguration { /** * Whether or not {@linkplain #locations resource locations} or * {@linkplain #classes component classes} from test superclasses - * should be inherited. + * and enclosing classes should be inherited. *
The default value is {@code true}. This means that an annotated test * class will inherit the resource locations or component classes - * defined by test superclasses. Specifically, the resource locations or - * component classes for a given test class will be appended to the list of - * resource locations or component classes defined by test superclasses. - * Thus, subclasses have the option of extending the list of resource + * defined by test superclasses and enclosing classes. Specifically, the + * resource locations or component classes for a given test class will be + * appended to the list of resource locations or component classes defined + * by test superclasses and enclosing classes. Thus, subclasses and nested + * classes have the option of extending the list of resource * locations or component classes. *
If {@code inheritLocations} is set to {@code false}, the * resource locations or component classes for the annotated test class * will shadow and effectively replace any resource locations - * or component classes defined by superclasses. + * or component classes defined by superclasses and enclosing classes. *
In the following example that uses path-based resource locations, the * {@link org.springframework.context.ApplicationContext ApplicationContext} * for {@code ExtendedTest} will be loaded from @@ -225,16 +226,16 @@ public @interface ContextConfiguration { /** * Whether or not {@linkplain #initializers context initializers} from test - * superclasses should be inherited. + * superclasses and enclosing classes should be inherited. *
The default value is {@code true}. This means that an annotated test * class will inherit the application context initializers defined - * by test superclasses. Specifically, the initializers for a given test - * class will be added to the set of initializers defined by test - * superclasses. Thus, subclasses have the option of extending the - * set of initializers. + * by test superclasses and enclosing classes. Specifically, the initializers + * for a given test class will be added to the set of initializers defined by + * test superclasses and enclosing classes. Thus, subclasses and nested classes + * have the option of extending the set of initializers. *
If {@code inheritInitializers} is set to {@code false}, the initializers * for the annotated test class will shadow and effectively replace - * any initializers defined by superclasses. + * any initializers defined by superclasses and enclosing classes. *
In the following example, the * {@link org.springframework.context.ApplicationContext ApplicationContext} * for {@code ExtendedTest} will be initialized using @@ -263,9 +264,10 @@ public @interface ContextConfiguration { * for loading an {@link org.springframework.context.ApplicationContext * ApplicationContext}. *
If not specified, the loader will be inherited from the first superclass - * that is annotated or meta-annotated with {@code @ContextConfiguration} and - * specifies an explicit loader. If no class in the hierarchy specifies an - * explicit loader, a default loader will be used instead. + * or enclosing class that is annotated or meta-annotated with + * {@code @ContextConfiguration} and specifies an explicit loader. If no class + * in the type hierarchy or enclosing class hierarchy specifies an explicit + * loader, a default loader will be used instead. *
The default concrete implementation chosen at runtime will be either * {@link org.springframework.test.context.support.DelegatingSmartContextLoader * DelegatingSmartContextLoader} or @@ -290,10 +292,12 @@ public @interface ContextConfiguration { *
If not specified the name will be inferred based on the numerical level * within all declared contexts within the hierarchy. *
This attribute is only applicable when used within a test class hierarchy - * that is configured using {@code @ContextHierarchy}, in which case the name - * can be used for merging or overriding this configuration - * with configuration of the same name in hierarchy levels defined in superclasses. - * See the Javadoc for {@link ContextHierarchy @ContextHierarchy} for details. + * or enclosing class hierarchy that is configured using + * {@code @ContextHierarchy}, in which case the name can be used for + * merging or overriding this configuration with configuration + * of the same name in hierarchy levels defined in superclasses or enclosing + * classes. See the Javadoc for {@link ContextHierarchy @ContextHierarchy} for + * details. * @since 3.2.2 */ String name() default ""; diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java index 34b3380446..e2ff0a4502 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public interface ContextCustomizerFactory { * @param testClass the test class * @param configAttributes the list of context configuration attributes for * the test class, ordered bottom-up (i.e., as if we were traversing - * up the class hierarchy); never {@code null} or empty + * up the class hierarchy or enclosing class hierarchy); never {@code null} or empty * @return a {@link ContextCustomizer} or {@code null} if no customizer should * be used */ diff --git a/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java index 318d9d0f8c..97841c8c80 100644 --- a/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,16 +31,16 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** - * {@code MergedContextConfiguration} encapsulates the merged - * context configuration declared on a test class and all of its superclasses - * via {@link ContextConfiguration @ContextConfiguration}, + * {@code MergedContextConfiguration} encapsulates the merged context + * configuration declared on a test class and all of its superclasses and + * enclosing classes via {@link ContextConfiguration @ContextConfiguration}, * {@link ActiveProfiles @ActiveProfiles}, and * {@link TestPropertySource @TestPropertySource}. * *
Merged context resource locations, annotated classes, active profiles,
* property resource locations, and in-lined properties represent all declared
- * values in the test class hierarchy taking into consideration the semantics
- * of the {@link ContextConfiguration#inheritLocations},
+ * values in the test class hierarchy and enclosing class hierarchy taking into
+ * consideration the semantics of the {@link ContextConfiguration#inheritLocations},
* {@link ActiveProfiles#inheritProfiles},
* {@link TestPropertySource#inheritLocations}, and
* {@link TestPropertySource#inheritProperties} flags.
diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/TestContextBootstrapper.java
index 858cff89c6..27e33676d1 100644
--- a/spring-test/src/main/java/org/springframework/test/context/TestContextBootstrapper.java
+++ b/spring-test/src/main/java/org/springframework/test/context/TestContextBootstrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -126,7 +126,8 @@ public interface TestContextBootstrapper {
* flag of {@link TestExecutionListeners @TestExecutionListeners} must be
* taken into consideration. Specifically, if the {@code inheritListeners}
* flag is set to {@code true}, listeners declared for a given test class must
- * be appended to the end of the list of listeners declared in superclasses.
+ * be appended to the end of the list of listeners declared in superclasses
+ * or enclosing classes.
* @return a list of {@code TestExecutionListener} instances
*/
List The default value is {@code true}, which means that an annotated
- * class will inherit the listeners defined by an annotated
- * superclass. Specifically, the listeners for an annotated class will be
- * appended to the list of listeners defined by an annotated superclass.
- * Thus, subclasses have the option of extending the list of
- * listeners. In the following example, {@code AbstractBaseTest} will
- * be configured with {@code DependencyInjectionTestExecutionListener}
- * and {@code DirtiesContextTestExecutionListener}; whereas,
+ * and enclosing classes should be inherited.
+ * The default value is {@code true}, which means that an annotated class
+ * will inherit the listeners defined by an annotated superclass or
+ * enclosing class. Specifically, the listeners for an annotated class will be
+ * appended to the list of listeners defined by an annotated superclass or
+ * enclosing class. Thus, subclasses and nested classes have the option of
+ * extending the list of listeners. In the following example,
+ * {@code AbstractBaseTest} will be configured with
+ * {@code DependencyInjectionTestExecutionListener} and
+ * {@code DirtiesContextTestExecutionListener}; whereas,
* {@code TransactionalTest} will be configured with
* {@code DependencyInjectionTestExecutionListener},
* {@code DirtiesContextTestExecutionListener}, and
@@ -107,18 +108,19 @@ public @interface TestExecutionListeners {
* }
* If {@code inheritListeners} is set to {@code false}, the listeners for
* the annotated class will shadow and effectively replace any
- * listeners defined by a superclass.
+ * listeners defined by a superclass or enclosing class.
*/
boolean inheritListeners() default true;
/**
* The merge mode to use when {@code @TestExecutionListeners} is
- * declared on a class that does not inherit listeners
- * from a superclass.
+ * declared on a class that does not inherit listeners from
+ * a superclass or enclosing class.
* Can be set to {@link MergeMode#MERGE_WITH_DEFAULTS MERGE_WITH_DEFAULTS}
* to have locally declared listeners merged with the default
* listeners.
- * The mode is ignored if listeners are inherited from a superclass.
+ * The mode is ignored if listeners are inherited from a superclass or
+ * enclosing class.
* Defaults to {@link MergeMode#REPLACE_DEFAULTS REPLACE_DEFAULTS}
* for backwards compatibility.
* @see MergeMode
@@ -131,7 +133,8 @@ public @interface TestExecutionListeners {
* Enumeration of modes that dictate whether or not explicitly
* declared listeners are merged with the default listeners when
* {@code @TestExecutionListeners} is declared on a class that does
- * not inherit listeners from a superclass.
+ * not inherit listeners from a superclass or enclosing
+ * class.
* @since 4.1
*/
enum MergeMode {
diff --git a/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java b/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java
index f74b9c5c62..cdbdbc472b 100644
--- a/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java
+++ b/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -151,16 +151,18 @@ public @interface TestPropertySource {
/**
* Whether or not test property source {@link #locations} from superclasses
- * should be inherited.
+ * and enclosing classes should be inherited.
* The default value is {@code true}, which means that a test class will
- * inherit property source locations defined by a superclass.
- * Specifically, the property source locations for a test class will be
- * appended to the list of property source locations defined by a superclass.
- * Thus, subclasses have the option of extending the list of test
- * property source locations.
+ * inherit property source locations defined by a superclass or
+ * enclosing class. Specifically, the property source locations for a test
+ * class will be appended to the list of property source locations defined
+ * by a superclass or enclosing class. Thus, subclasses and nested classes
+ * have the option of extending the list of test property source
+ * locations.
* If {@code inheritLocations} is set to {@code false}, the property
* source locations for the test class will shadow and effectively
- * replace any property source locations defined by a superclass.
+ * replace any property source locations defined by a superclass or
+ * enclosing class.
* In the following example, the {@code ApplicationContext} for
* {@code BaseTest} will be loaded using only the {@code "base.properties"}
* file as a test property source. In contrast, the {@code ApplicationContext}
@@ -228,16 +230,17 @@ public @interface TestPropertySource {
String[] properties() default {};
/**
- * Whether or not inlined test {@link #properties} from superclasses should
- * be inherited.
+ * Whether or not inlined test {@link #properties} from superclasses and
+ * enclosing classes should be inherited.
* The default value is {@code true}, which means that a test class will
- * inherit inlined properties defined by a superclass. Specifically,
- * the inlined properties for a test class will be appended to the list of
- * inlined properties defined by a superclass. Thus, subclasses have the
- * option of extending the list of inlined test properties.
+ * inherit inlined properties defined by a superclass or enclosing
+ * class. Specifically, the inlined properties for a test class will be
+ * appended to the list of inlined properties defined by a superclass or
+ * enclosing class. Thus, subclasses and nested classes have the option of
+ * extending the list of inlined test properties.
* If {@code inheritProperties} is set to {@code false}, the inlined
* properties for the test class will shadow and effectively
- * replace any inlined properties defined by a superclass.
+ * replace any inlined properties defined by a superclass or enclosing class.
* In the following example, the {@code ApplicationContext} for
* {@code BaseTest} will be loaded using only the inlined {@code key1}
* property. In contrast, the {@code ApplicationContext} for
@@ -261,7 +264,7 @@ public @interface TestPropertySource {
* test class hierarchy (i.e., directly present or meta-present on a test
* class) are considered to be local annotations, in contrast to
* {@code @TestPropertySource} annotations that are inherited from a
- * superclass.
+ * superclass or enclosing class.
* This annotation may be used as a meta-annotation to create custom
* composed annotations.
*
+ * This annotation will be inherited from an enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @since 5.3.3
* @see ApplicationEvents
diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java
index fb69e925c0..9b09eb9162 100644
--- a/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java
+++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,6 +53,11 @@ import org.springframework.core.annotation.AliasFor;
* This annotation may be used as a meta-annotation to create custom
* composed annotations with attribute overrides.
*
+ * As of Spring Framework 5.3, this annotation will be inherited from an
+ * enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @since 4.1
* @see SqlConfig
diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java
index c3487bdf3b..c42cb28bfc 100644
--- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java
+++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,6 +54,11 @@ import java.lang.annotation.Target;
* {@code ""}, As of Spring Framework 5.3, this annotation will be inherited from an
+ * enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @author Tadaya Tsuyukubo
* @since 4.1
diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java
index 241c584aa0..75f8aa36c5 100644
--- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java
+++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,11 @@ import java.lang.annotation.Target;
* This annotation may be used as a meta-annotation to create custom
* composed annotations.
*
+ * As of Spring Framework 5.3, this annotation will be inherited from an
+ * enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @since 4.1
* @see Sql
diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlMergeMode.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlMergeMode.java
index 352eb68da9..6479a85524 100644
--- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlMergeMode.java
+++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlMergeMode.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,11 @@ import java.lang.annotation.Target;
* This annotation may be used as a meta-annotation to create custom
* composed annotations with attribute overrides.
*
+ * As of Spring Framework 5.3, this annotation will be inherited from an
+ * enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @author Dmitry Semukhin
* @since 5.2
diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringJUnitConfig.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringJUnitConfig.java
index 9b72ce930d..af6f837048 100644
--- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringJUnitConfig.java
+++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringJUnitConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,11 @@ import org.springframework.test.context.ContextConfiguration;
* {@link ContextConfiguration @ContextConfiguration} from the Spring TestContext
* Framework.
*
+ * As of Spring Framework 5.3, this annotation will effectively be inherited
+ * from an enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @since 5.0
* @see ExtendWith
diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/SpringJUnitWebConfig.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/SpringJUnitWebConfig.java
index f80ad555ea..614faa7003 100644
--- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/SpringJUnitWebConfig.java
+++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/SpringJUnitWebConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,11 @@ import org.springframework.test.context.web.WebAppConfiguration;
* {@link WebAppConfiguration @WebAppConfiguration} from the Spring TestContext
* Framework.
*
+ * As of Spring Framework 5.3, this annotation will effectively be inherited
+ * from an enclosing test class by default. See
+ * {@link org.springframework.test.context.NestedTestConfiguration @NestedTestConfiguration}
+ * for details.
+ *
* @author Sam Brannen
* @since 5.0
* @see ExtendWith
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
index 5421e28214..4c323cae46 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
@@ -37,9 +37,10 @@ import org.springframework.util.Assert;
* configuration. Each candidate is given a chance to
* {@linkplain #processContextConfiguration process} the
* {@link ContextConfigurationAttributes} for each class in the test class hierarchy
- * that is annotated with {@link ContextConfiguration @ContextConfiguration}, and
- * the candidate that supports the merged, processed configuration will be used to
- * actually {@linkplain #loadContext load} the context.
+ * and enclosing class hierarchy that is annotated with
+ * {@link ContextConfiguration @ContextConfiguration}, and the candidate that
+ * supports the merged, processed configuration will be used to actually
+ * {@linkplain #loadContext load} the context.
*
* Any reference to an XML-based loader can be interpreted to mean
* a context loader that supports only XML configuration files or one that
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
index 17bddaf5b4..4feab44b3e 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -318,7 +318,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
* should be built (must not be {@code null})
* @param configAttributesList the list of context configuration attributes for the
* specified test class, ordered bottom-up (i.e., as if we were
- * traversing up the class hierarchy); never {@code null} or empty
+ * traversing up the class hierarchy and enclosing class hierarchy); never
+ * {@code null} or empty
* @param parentConfig the merged context configuration for the parent application
* context in a context hierarchy, or {@code null} if there is no parent
* @param cacheAwareContextLoaderDelegate the cache-aware context loader delegate to
@@ -431,7 +432,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
* resolved; must not be {@code null}
* @param configAttributesList the list of configuration attributes to process; must
* not be {@code null}; must be ordered bottom-up
- * (i.e., as if we were traversing up the class hierarchy)
+ * (i.e., as if we were traversing up the class hierarchy and enclosing class hierarchy)
* @return the resolved {@code ContextLoader} for the supplied {@code testClass}
* (never {@code null})
* @throws IllegalStateException if {@link #getDefaultContextLoaderClass(Class)}
@@ -468,7 +469,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
*
* @param configAttributesList the list of configuration attributes to process;
* must not be {@code null}; must be ordered bottom-up
- * (i.e., as if we were traversing up the class hierarchy)
+ * (i.e., as if we were traversing up the class hierarchy and enclosing class hierarchy)
* @return the {@code ContextLoader} class to use for the supplied configuration
* attributes, or {@code null} if no explicit loader is found
* @throws IllegalArgumentException if supplied configuration attributes are
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java
index 2354de61bd..b994e77784 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,11 +60,12 @@ abstract class ActiveProfilesUtils {
* Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles} flag of
* {@link ActiveProfiles @ActiveProfiles} will be taken into consideration.
* Specifically, if the {@code inheritProfiles} flag is set to {@code true}, profiles
- * defined in the test class will be merged with those defined in superclasses.
+ * defined in the test class will be merged with those defined in superclasses
+ * and enclosing classes.
* @param testClass the class for which to resolve the active profiles (must not be
* {@code null})
* @return the set of active profiles for the specified class, including active
- * profiles from superclasses if appropriate (never {@code null})
+ * profiles from superclasses and enclosing classes if appropriate (never {@code null})
* @see ActiveProfiles
* @see ActiveProfilesResolver
* @see org.springframework.context.annotation.Profile
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java
index d7b395f2b2..91938297e5 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,12 +52,13 @@ abstract class ApplicationContextInitializerUtils {
* Note that the {@link ContextConfiguration#inheritInitializers inheritInitializers}
* flag of {@link ContextConfiguration @ContextConfiguration} will be taken into
* consideration. Specifically, if the {@code inheritInitializers} flag is set to
- * {@code true} for a given level in the class hierarchy represented by the provided
- * configuration attributes, context initializer classes defined at the given level
- * will be merged with those defined in higher levels of the class hierarchy.
+ * {@code true} for a given level in the class hierarchy and enclosing class
+ * hierarchy represented by the provided configuration attributes, context
+ * initializer classes defined at the given level will be merged with those
+ * defined in higher levels of the class hierarchy or enclosing class hierarchy.
* @param configAttributesList the list of configuration attributes to process; must
* not be {@code null} or empty; must be ordered bottom-up
- * (i.e., as if we were traversing up the class hierarchy)
+ * (i.e., as if we were traversing up the class hierarchy or enclosing class hierarchy)
* @return the set of merged context initializer classes, including those from
* superclasses if appropriate (never {@code null})
* @since 3.2
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java
index 8e37932c55..96bcce7623 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,17 +63,17 @@ abstract class ContextLoaderUtils {
/**
* Resolve the list of lists of {@linkplain ContextConfigurationAttributes context
* configuration attributes} for the supplied {@linkplain Class test class} and its
- * superclasses, taking into account context hierarchies declared via
- * {@link ContextHierarchy @ContextHierarchy} and
+ * superclasses and enclosing classes, taking into account context hierarchies
+ * declared via {@link ContextHierarchy @ContextHierarchy} and
* {@link ContextConfiguration @ContextConfiguration}.
* The outer list represents a top-down ordering of context configuration
* attributes, where each element in the list represents the context configuration
- * declared on a given test class in the class hierarchy. Each nested list
- * contains the context configuration attributes declared either via a single
- * instance of {@code @ContextConfiguration} on the particular class or via
- * multiple instances of {@code @ContextConfiguration} declared within a
- * single {@code @ContextHierarchy} instance on the particular class.
- * Furthermore, each nested list maintains the order in which
+ * declared on a given test class in the class hierarchy or enclosing class
+ * hierarchy. Each nested list contains the context configuration attributes
+ * declared either via a single instance of {@code @ContextConfiguration} on
+ * the particular class or via multiple instances of {@code @ContextConfiguration}
+ * declared within a single {@code @ContextHierarchy} instance on the particular
+ * class. Furthermore, each nested list maintains the order in which
* {@code @ContextConfiguration} instances are declared.
* Note that the {@link ContextConfiguration#inheritLocations inheritLocations} and
* {@link ContextConfiguration#inheritInitializers() inheritInitializers} flags of
@@ -157,14 +157,14 @@ abstract class ContextLoaderUtils {
/**
* Build a context hierarchy map for the supplied {@linkplain Class
- * test class} and its superclasses, taking into account context hierarchies
- * declared via {@link ContextHierarchy @ContextHierarchy} and
- * {@link ContextConfiguration @ContextConfiguration}.
+ * test class} and its superclasses and enclosing classes, taking into account
+ * context hierarchies declared via {@link ContextHierarchy @ContextHierarchy}
+ * and {@link ContextConfiguration @ContextConfiguration}.
* Each value in the map represents the consolidated list of {@linkplain
* ContextConfigurationAttributes context configuration attributes} for a
* given level in the context hierarchy (potentially across the test class
- * hierarchy), keyed by the {@link ContextConfiguration#name() name} of the
- * context hierarchy level.
+ * hierarchy and enclosing class hierarchy), keyed by the
+ * {@link ContextConfiguration#name() name} of the context hierarchy level.
* If a given level in the context hierarchy does not have an explicit
* name (i.e., configured via {@link ContextConfiguration#name}), a name will
* be generated for that hierarchy level by appending the numerical level to
@@ -217,8 +217,8 @@ abstract class ContextLoaderUtils {
/**
* Resolve the list of {@linkplain ContextConfigurationAttributes context
- * configuration attributes} for the supplied {@linkplain Class test class} and its
- * superclasses.
+ * configuration attributes} for the supplied {@linkplain Class test class}
+ * and its superclasses and enclosing classes.
* Note that the {@link ContextConfiguration#inheritLocations inheritLocations} and
* {@link ContextConfiguration#inheritInitializers() inheritInitializers} flags of
* {@link ContextConfiguration @ContextConfiguration} will not
@@ -227,8 +227,8 @@ abstract class ContextLoaderUtils {
* @param testClass the class for which to resolve the configuration attributes
* (must not be {@code null})
* @return the list of configuration attributes for the specified class, ordered
- * bottom-up (i.e., as if we were traversing up the class hierarchy);
- * never {@code null}
+ * bottom-up (i.e., as if we were traversing up the class hierarchy
+ * and enclosing class hierarchy); never {@code null}
* @throws IllegalArgumentException if the supplied class is {@code null} or if
* {@code @ContextConfiguration} is not present on the supplied class
*/
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java b/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java
index ee7e31d00e..0ffa7689ef 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java
@@ -24,9 +24,9 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.util.Assert;
/**
- * {@code MergedTestPropertySources} encapsulates the merged
- * property sources declared on a test class and all of its superclasses
- * via {@link TestPropertySource @TestPropertySource}.
+ * {@code MergedTestPropertySources} encapsulates the merged property
+ * sources declared on a test class and all of its superclasses and enclosing
+ * classes via {@link TestPropertySource @TestPropertySource}.
*
* @author Sam Brannen
* @since 4.1
diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
index a64897e841..843619bd25 100644
--- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
+++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
@@ -73,10 +73,10 @@ import org.springframework.util.StringUtils;
* to be run within a transaction that will, by default, be automatically
* rolled back after completion of the test. If a test class is
* annotated with {@code @Transactional}, each test method within that class
- * hierarchy will be run within a transaction. Test methods that are
- * not annotated with {@code @Transactional} (at the class or method
- * level) will not be run within a transaction. Furthermore, tests that
- * are annotated with {@code @Transactional} but have the
+ * hierarchy or nested class hierarchy will be run within a transaction. Test
+ * methods that are not annotated with {@code @Transactional} (at the
+ * class or method level) will not be run within a transaction. Furthermore,
+ * tests that are annotated with {@code @Transactional} but have the
* {@link Transactional#propagation propagation} type set to
* {@link org.springframework.transaction.annotation.Propagation#NOT_SUPPORTED NOT_SUPPORTED}
* or {@link org.springframework.transaction.annotation.Propagation#NEVER NEVER}
{}, or {@code DEFAULT}. Explicit local configuration
* therefore overrides global configuration.
*
+ *