Allow overriding dynamic property from enclosing class in nested test class

Prior to this commit, a dynamic property registered via a
@DynamicPropertySource method in a @Nested test class was not able to
override a property registered via a @DynamicPropertySource method in
the enclosing class.

See gh-26091
Closes gh-31083
This commit is contained in:
Yanming Zhou
2023-08-21 17:37:57 +08:00
committed by Sam Brannen
parent 8a6c0cd221
commit 368036cab4
2 changed files with 19 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
*
* @author Phillip Webb
* @author Sam Brannen
* @author Yanming Zhou
* @since 5.2.5
* @see DynamicPropertiesContextCustomizer
*/
@@ -54,10 +55,10 @@ class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFact
}
private void findMethods(Class<?> testClass, Set<Method> methods) {
methods.addAll(MethodIntrospector.selectMethods(testClass, this::isAnnotated));
if (TestContextAnnotationUtils.searchEnclosingClass(testClass)) {
findMethods(testClass.getEnclosingClass(), methods);
}
methods.addAll(MethodIntrospector.selectMethods(testClass, this::isAnnotated));
}
private boolean isAnnotated(Method method) {