Merge branch '6.2.x'

This commit is contained in:
Sam Brannen
2025-02-08 13:33:39 +01:00
3 changed files with 86 additions and 6 deletions

View File

@@ -131,7 +131,7 @@ public abstract class BeanOverrideHandler {
private static List<BeanOverrideHandler> findHandlers(Class<?> testClass, boolean localFieldsOnly) {
List<BeanOverrideHandler> handlers = new ArrayList<>();
findHandlers(testClass, testClass, handlers, localFieldsOnly);
findHandlers(testClass, testClass, handlers, localFieldsOnly, new HashSet<>());
return handlers;
}
@@ -145,26 +145,30 @@ public abstract class BeanOverrideHandler {
* @param testClass the original test class
* @param handlers the list of handlers found
* @param localFieldsOnly whether to search only on local fields within the type hierarchy
* @param visitedEnclosingClasses the set of enclosing classes already visited
* @since 6.2.2
*/
private static void findHandlers(Class<?> clazz, Class<?> testClass, List<BeanOverrideHandler> handlers,
boolean localFieldsOnly) {
boolean localFieldsOnly, Set<Class<?>> visitedEnclosingClasses) {
// 1) Search enclosing class hierarchy.
if (!localFieldsOnly && TestContextAnnotationUtils.searchEnclosingClass(clazz)) {
findHandlers(clazz.getEnclosingClass(), testClass, handlers, localFieldsOnly);
Class<?> enclosingClass = clazz.getEnclosingClass();
if (visitedEnclosingClasses.add(enclosingClass)) {
findHandlers(enclosingClass, testClass, handlers, localFieldsOnly, visitedEnclosingClasses);
}
}
// 2) Search class hierarchy.
Class<?> superclass = clazz.getSuperclass();
if (superclass != null && superclass != Object.class) {
findHandlers(superclass, testClass, handlers, localFieldsOnly);
findHandlers(superclass, testClass, handlers, localFieldsOnly, visitedEnclosingClasses);
}
if (!localFieldsOnly) {
// 3) Search interfaces.
for (Class<?> ifc : clazz.getInterfaces()) {
findHandlers(ifc, testClass, handlers, localFieldsOnly);
findHandlers(ifc, testClass, handlers, localFieldsOnly, visitedEnclosingClasses);
}
// 4) Process current class.