Refine ReflectiveProcessorBeanRegistrationAotProcessor
Add support for processing implemented interfaces and remove Reflective from runtime hints. See gh-28518
This commit is contained in:
@@ -48,6 +48,7 @@ import static org.mockito.Mockito.mock;
|
||||
* Tests for {@link ReflectiveProcessorBeanRegistrationAotProcessor}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
class ReflectiveProcessorBeanRegistrationAotProcessorTests {
|
||||
|
||||
@@ -109,6 +110,28 @@ class ReflectiveProcessorBeanRegistrationAotProcessorTests {
|
||||
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(RetryInvoker.class, SynthesizedAnnotation.class)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldProcessAnnotationOnInterface() {
|
||||
process(SampleMethodAnnotatedBeanWithInterface.class);
|
||||
assertThat(this.generationContext.getRuntimeHints().reflection().getTypeHint(SampleInterface.class))
|
||||
.satisfies(typeHint -> assertThat(typeHint.methods()).singleElement()
|
||||
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
|
||||
assertThat(this.generationContext.getRuntimeHints().reflection().getTypeHint(SampleMethodAnnotatedBeanWithInterface.class))
|
||||
.satisfies(typeHint -> assertThat(typeHint.methods()).singleElement()
|
||||
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldProcessAnnotationOnInheritedClass() {
|
||||
process(SampleMethodAnnotatedBeanWithInheritance.class);
|
||||
assertThat(this.generationContext.getRuntimeHints().reflection().getTypeHint(SampleInheritedClass.class))
|
||||
.satisfies(typeHint -> assertThat(typeHint.methods()).singleElement()
|
||||
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
|
||||
assertThat(this.generationContext.getRuntimeHints().reflection().getTypeHint(SampleMethodAnnotatedBeanWithInheritance.class))
|
||||
.satisfies(typeHint -> assertThat(typeHint.methods()).singleElement()
|
||||
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BeanRegistrationAotContribution createContribution(Class<?> beanClass) {
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
@@ -193,6 +216,28 @@ class ReflectiveProcessorBeanRegistrationAotProcessorTests {
|
||||
|
||||
}
|
||||
|
||||
static class SampleMethodAnnotatedBeanWithInterface implements SampleInterface {
|
||||
|
||||
@Override
|
||||
public void managed() {
|
||||
}
|
||||
|
||||
public void notManaged() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class SampleMethodAnnotatedBeanWithInheritance extends SampleInheritedClass {
|
||||
|
||||
@Override
|
||||
public void managed() {
|
||||
}
|
||||
|
||||
public void notManaged() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@@ -214,4 +259,17 @@ class ReflectiveProcessorBeanRegistrationAotProcessorTests {
|
||||
|
||||
}
|
||||
|
||||
interface SampleInterface {
|
||||
|
||||
@Reflective
|
||||
void managed();
|
||||
}
|
||||
|
||||
static class SampleInheritedClass {
|
||||
|
||||
@Reflective
|
||||
void managed() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user