|
21 | 21 | import java.lang.annotation.Retention;
|
22 | 22 | import java.lang.annotation.RetentionPolicy;
|
23 | 23 | import java.lang.annotation.Target;
|
| 24 | +import java.lang.reflect.Method; |
24 | 25 |
|
25 | 26 | import org.junit.jupiter.api.Test;
|
26 | 27 |
|
| 28 | +import org.springframework.aot.hint.MemberCategory; |
| 29 | +import org.springframework.aot.hint.ReflectionHints; |
27 | 30 | import org.springframework.aot.hint.RuntimeHints;
|
28 | 31 | import org.springframework.aot.hint.TypeReference;
|
29 | 32 | import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
@@ -121,6 +124,16 @@ void shouldProcessAnnotationOnInheritedClass() {
|
121 | 124 | .satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
|
122 | 125 | }
|
123 | 126 |
|
| 127 | + @Test |
| 128 | + void shouldInvokeCustomProcessor() { |
| 129 | + process(SampleCustomProcessor.class); |
| 130 | + assertThat(RuntimeHintsPredicates.reflection() |
| 131 | + .onMethod(SampleCustomProcessor.class, "managed")).accepts(this.runtimeHints); |
| 132 | + assertThat(RuntimeHintsPredicates.reflection().onType(String.class) |
| 133 | + .withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints); |
| 134 | + |
| 135 | + } |
| 136 | + |
124 | 137 | private void process(Class<?> beanClass) {
|
125 | 138 | this.registrar.registerRuntimeHints(this.runtimeHints, beanClass);
|
126 | 139 | }
|
@@ -252,4 +265,24 @@ void managed() {
|
252 | 265 | }
|
253 | 266 | }
|
254 | 267 |
|
| 268 | + static class SampleCustomProcessor { |
| 269 | + |
| 270 | + @Reflective(TestReflectiveProcessor.class) |
| 271 | + public String managed() { |
| 272 | + return "test"; |
| 273 | + } |
| 274 | + |
| 275 | + } |
| 276 | + |
| 277 | + private static class TestReflectiveProcessor extends SimpleReflectiveProcessor { |
| 278 | + |
| 279 | + @Override |
| 280 | + protected void registerMethodHint(ReflectionHints hints, Method method) { |
| 281 | + super.registerMethodHint(hints, method); |
| 282 | + hints.registerType(method.getReturnType(), type -> |
| 283 | + type.withMembers(MemberCategory.INVOKE_DECLARED_METHODS)); |
| 284 | + } |
| 285 | + |
| 286 | + } |
| 287 | + |
255 | 288 | }
|
0 commit comments