Polish "Handle inferred init/destroy method consistently"
See gh-28843
This commit is contained in:
@@ -245,6 +245,13 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
||||
assertHasMethodInvokeHints(InitDestroyBean.class, methodNames);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setInitMethodWithInferredMethodFirst() {
|
||||
this.beanDefinition.setInitMethodNames(AbstractBeanDefinition.INFER_METHOD, "init");
|
||||
compile((actual, compiled) -> assertThat(compiled.getSourceFile().getContent())
|
||||
.contains("beanDefinition.setInitMethodNames(\"init\");"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void setDestroyMethodWhenDestroyInitMethod() {
|
||||
this.beanDefinition.setTargetType(InitDestroyBean.class);
|
||||
@@ -274,6 +281,13 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
||||
assertHasMethodInvokeHints(InitDestroyBean.class, methodNames);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setDestroyMethodWithInferredMethodFirst() {
|
||||
this.beanDefinition.setDestroyMethodNames(AbstractBeanDefinition.INFER_METHOD, "destroy");
|
||||
compile((actual, compiled) -> assertThat(compiled.getSourceFile().getContent())
|
||||
.contains("beanDefinition.setDestroyMethodNames(\"destroy\");"));
|
||||
}
|
||||
|
||||
private void assertHasMethodInvokeHints(Class<?> beanType, String... methodNames) {
|
||||
assertThat(methodNames).allMatch(methodName -> RuntimeHintsPredicates.reflection()
|
||||
.onMethod(beanType, methodName).invoke()
|
||||
@@ -395,18 +409,6 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void inferredMethodsAtTheBeginning() {
|
||||
this.beanDefinition.setInitMethodNames(AbstractBeanDefinition.INFER_METHOD, "init");
|
||||
this.beanDefinition.setDestroyMethodNames(AbstractBeanDefinition.INFER_METHOD, "destroy");
|
||||
compile((actual, compiled) -> {
|
||||
assertThat(compiled.getSourceFile().getContent())
|
||||
.contains("beanDefinition.setInitMethodNames(\"init\");");
|
||||
assertThat(compiled.getSourceFile().getContent())
|
||||
.contains("beanDefinition.setDestroyMethodNames(\"destroy\");");
|
||||
});
|
||||
}
|
||||
|
||||
private void compile(BiConsumer<RootBeanDefinition, Compiled> result) {
|
||||
compile(attribute -> true, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user