Fix AOT code generation for managed types.
Closes #2704 Original pull request: #2705.
This commit is contained in:
committed by
Mark Paluch
parent
b55f098b43
commit
1fde452ab9
@@ -195,6 +195,28 @@ class ManagedTypesBeanRegistrationAotProcessorUnitTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // GH-2680
|
||||
void generatesInstanceSupplierCodeFragmentToAvoidDuplicateInvocationsForEmptyManagedTypes() {
|
||||
|
||||
beanFactory.registerBeanDefinition("commons.managed-types", BeanDefinitionBuilder.rootBeanDefinition(EmptyManagedTypes.class).getBeanDefinition());
|
||||
RegisteredBean registeredBean = RegisteredBean.of(beanFactory, "commons.managed-types");
|
||||
|
||||
BeanRegistrationAotContribution contribution = createPostProcessor("commons")
|
||||
.processAheadOfTime(RegisteredBean.of(beanFactory, "commons.managed-types"));
|
||||
|
||||
AotTestCodeContributionBuilder.withContextFor(this.getClass()).writeContentFor(contribution).compile(it -> {
|
||||
|
||||
|
||||
InstanceSupplier<ManagedTypes> types = ReflectionTestUtils
|
||||
.invokeMethod(it.getAllCompiledClasses().iterator().next(), "instance");
|
||||
try {
|
||||
assertThat(types.get(registeredBean).toList()).isEmpty();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test // GH-2680
|
||||
void generatesInstanceSupplierCodeFragmentForTypeWithCustomFactoryMethod() {
|
||||
|
||||
@@ -269,6 +291,22 @@ class ManagedTypesBeanRegistrationAotProcessorUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmptyManagedTypes implements ManagedTypes {
|
||||
|
||||
public EmptyManagedTypes() {
|
||||
|
||||
}
|
||||
|
||||
public static EmptyManagedTypes of(ManagedTypes source) {
|
||||
return new EmptyManagedTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<Class<?>> action) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class StoreManagedTypesWithCustomFactoryMethod implements ManagedTypes {
|
||||
|
||||
private ManagedTypes source;
|
||||
|
||||
Reference in New Issue
Block a user