|
19 | 19 | import java.lang.reflect.Constructor; |
20 | 20 | import java.lang.reflect.Field; |
21 | 21 | import java.lang.reflect.Modifier; |
| 22 | +import java.util.ArrayList; |
22 | 23 | import java.util.HashMap; |
23 | 24 | import java.util.List; |
24 | 25 | import java.util.Map; |
@@ -109,12 +110,20 @@ public void afterAll(ExtensionContext context) { |
109 | 110 | } |
110 | 111 |
|
111 | 112 | private void applyDeclaredConfig(ExtensionContext context) { |
112 | | - // Class-level @WithConfig annotations (supports composed/meta-annotations) |
113 | | - List<WithConfig> classConfigs = |
114 | | - AnnotationSupport.findRepeatableAnnotations( |
115 | | - context.getRequiredTestClass(), WithConfig.class); |
116 | | - for (WithConfig cfg : classConfigs) { |
117 | | - applyConfig(cfg); |
| 113 | + // Class-level @WithConfig annotations |
| 114 | + // Walk the entire class hierarchy so annotations on superclasses are applied |
| 115 | + // (topmost first, then subclass overrides) |
| 116 | + Class<?> testClass = context.getRequiredTestClass(); |
| 117 | + List<Class<?>> hierarchy = new ArrayList<>(); |
| 118 | + for (Class<?> cls = testClass; cls != null; cls = cls.getSuperclass()) { |
| 119 | + hierarchy.add(cls); |
| 120 | + } |
| 121 | + for (int i = hierarchy.size() - 1; i >= 0; i--) { |
| 122 | + List<WithConfig> classConfigs = |
| 123 | + AnnotationSupport.findRepeatableAnnotations(hierarchy.get(i), WithConfig.class); |
| 124 | + for (WithConfig cfg : classConfigs) { |
| 125 | + applyConfig(cfg); |
| 126 | + } |
118 | 127 | } |
119 | 128 | // Method-level @WithConfig annotations (supports composed/meta-annotations) |
120 | 129 | context |
|
0 commit comments