This commit is contained in:
Stéphane Nicoll
2023-12-12 11:44:53 +01:00
parent 134bb6e31f
commit b85fcb6aec

View File

@@ -28,7 +28,6 @@ import java.util.function.Supplier;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
@@ -440,21 +439,19 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@Nested @Nested
class InitDestroyMethodTests { class InitDestroyMethodTests {
private final String privateInitMethod = InitDestroyBean.class.getName() + ".privateInit"; private static final String privateInitMethod = InitDestroyBean.class.getName() + ".privateInit";
private final String privateDestroyMethod = InitDestroyBean.class.getName() + ".privateDestroy";
@BeforeEach private static final String privateDestroyMethod = InitDestroyBean.class.getName() + ".privateDestroy";
void setTargetType() {
beanDefinition.setTargetType(InitDestroyBean.class);
}
@Test @Test
void noInitMethod() { void noInitMethod() {
beanDefinition.setTargetType(InitDestroyBean.class);
compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).isNull()); compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).isNull());
} }
@Test @Test
void singleInitMethod() { void singleInitMethod() {
beanDefinition.setTargetType(InitDestroyBean.class);
beanDefinition.setInitMethodName("init"); beanDefinition.setInitMethodName("init");
compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).containsExactly("init")); compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).containsExactly("init"));
assertHasMethodInvokeHints(InitDestroyBean.class, "init"); assertHasMethodInvokeHints(InitDestroyBean.class, "init");
@@ -462,6 +459,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@Test @Test
void privateInitMethod() { void privateInitMethod() {
beanDefinition.setTargetType(InitDestroyBean.class);
beanDefinition.setInitMethodName(privateInitMethod); beanDefinition.setInitMethodName(privateInitMethod);
compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).containsExactly(privateInitMethod)); compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).containsExactly(privateInitMethod));
assertHasMethodInvokeHints(InitDestroyBean.class, "privateInit"); assertHasMethodInvokeHints(InitDestroyBean.class, "privateInit");
@@ -469,6 +467,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@Test @Test
void multipleInitMethods() { void multipleInitMethods() {
beanDefinition.setTargetType(InitDestroyBean.class);
beanDefinition.setInitMethodNames("init", privateInitMethod); beanDefinition.setInitMethodNames("init", privateInitMethod);
compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).containsExactly("init", privateInitMethod)); compile((beanDef, compiled) -> assertThat(beanDef.getInitMethodNames()).containsExactly("init", privateInitMethod));
assertHasMethodInvokeHints(InitDestroyBean.class, "init", "privateInit"); assertHasMethodInvokeHints(InitDestroyBean.class, "init", "privateInit");
@@ -476,12 +475,14 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@Test @Test
void noDestroyMethod() { void noDestroyMethod() {
beanDefinition.setTargetType(InitDestroyBean.class);
compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).isNull()); compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).isNull());
assertReflectionOnPublisher(); assertReflectionOnPublisher();
} }
@Test @Test
void singleDestroyMethod() { void singleDestroyMethod() {
beanDefinition.setTargetType(InitDestroyBean.class);
beanDefinition.setDestroyMethodName("destroy"); beanDefinition.setDestroyMethodName("destroy");
compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).containsExactly("destroy")); compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).containsExactly("destroy"));
assertHasMethodInvokeHints(InitDestroyBean.class, "destroy"); assertHasMethodInvokeHints(InitDestroyBean.class, "destroy");
@@ -490,6 +491,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@Test @Test
void privateDestroyMethod() { void privateDestroyMethod() {
beanDefinition.setTargetType(InitDestroyBean.class);
beanDefinition.setDestroyMethodName(privateDestroyMethod); beanDefinition.setDestroyMethodName(privateDestroyMethod);
compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).containsExactly(privateDestroyMethod)); compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).containsExactly(privateDestroyMethod));
assertHasMethodInvokeHints(InitDestroyBean.class, "privateDestroy"); assertHasMethodInvokeHints(InitDestroyBean.class, "privateDestroy");
@@ -498,6 +500,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@Test @Test
void multipleDestroyMethods() { void multipleDestroyMethods() {
beanDefinition.setTargetType(InitDestroyBean.class);
beanDefinition.setDestroyMethodNames("destroy", privateDestroyMethod); beanDefinition.setDestroyMethodNames("destroy", privateDestroyMethod);
compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).containsExactly("destroy", privateDestroyMethod)); compile((beanDef, compiled) -> assertThat(beanDef.getDestroyMethodNames()).containsExactly("destroy", privateDestroyMethod));
assertHasMethodInvokeHints(InitDestroyBean.class, "destroy", "privateDestroy"); assertHasMethodInvokeHints(InitDestroyBean.class, "destroy", "privateDestroy");