From 4d961fa472be9a1c411977eb928524a24933ec1f Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:59:39 +0200 Subject: [PATCH] =?UTF-8?q?Find=20@=E2=81=A0TestBean=20factory=20methods?= =?UTF-8?q?=20in=20multi-level=20@=E2=81=A0Nested=20hierarchy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this commit, a @⁠TestBean factory method was found in the directly enclosing class for a @⁠Nested test class; however, such a factory method was not found in the enclosing class of the enclosing class, etc. This commit updates the search algorithm for @⁠TestBean factory methods so that it recursively searches the enclosing class hierarchy for @⁠Nested test classes. Closes gh-32951 --- .../bean/override/convention/TestBean.java | 7 +- .../convention/TestBeanOverrideProcessor.java | 13 +- ...NestingLevelsTestBeanIntegrationTests.java | 131 ++++++++++++++++++ .../convention/TestBeanIntegrationTests.java | 37 +++++ 4 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 spring-test/src/test/java/org/springframework/test/context/bean/override/convention/MultipleNestingLevelsTestBeanIntegrationTests.java diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java index edb843bde7..d4cc67bb7a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java @@ -36,9 +36,10 @@ import org.springframework.test.context.bean.override.BeanOverride; * *

The instance is created from a zero-argument static factory method in the * test class whose return type is compatible with the annotated field. In the - * case of a nested test class, the enclosing class is also considered. Similarly, - * if the test class extends from a base class or implements any interfaces, the - * entire type hierarchy is considered. The method is deduced as follows. + * case of a nested test class, the enclosing class hierarchy is also considered. + * Similarly, if the test class extends from a base class or implements any + * interfaces, the entire type hierarchy is considered. The method is deduced as + * follows. *