|
|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.beans.factory.support; |
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
@ -59,13 +60,38 @@ class RootBeanDefinitionTests {
@@ -59,13 +60,38 @@ class RootBeanDefinitionTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void resolveDestroyMethodWithMatchingCandidateReplacedInferredVaue() { |
|
|
|
|
void resolveDestroyMethodWithMatchingCandidateReplacedForCloseMethod() { |
|
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(BeanWithCloseMethod.class); |
|
|
|
|
beanDefinition.setDestroyMethodName(AbstractBeanDefinition.INFER_METHOD); |
|
|
|
|
beanDefinition.resolveDestroyMethodIfNecessary(); |
|
|
|
|
assertThat(beanDefinition.getDestroyMethodNames()).containsExactly("close"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void resolveDestroyMethodWithMatchingCandidateReplacedForShutdownMethod() { |
|
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(BeanWithShutdownMethod.class); |
|
|
|
|
beanDefinition.setDestroyMethodName(AbstractBeanDefinition.INFER_METHOD); |
|
|
|
|
beanDefinition.resolveDestroyMethodIfNecessary(); |
|
|
|
|
assertThat(beanDefinition.getDestroyMethodNames()).containsExactly("shutdown"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void resolveDestroyMethodWithMatchingCandidateReplacedForExecutorService() { |
|
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(BeanImplementingExecutorService.class); |
|
|
|
|
beanDefinition.setDestroyMethodName(AbstractBeanDefinition.INFER_METHOD); |
|
|
|
|
beanDefinition.resolveDestroyMethodIfNecessary(); |
|
|
|
|
assertThat(beanDefinition.getDestroyMethodNames()).containsExactly("shutdown"); |
|
|
|
|
// even on JDK 19+ where the ExecutorService interface declares a default AutoCloseable implementation
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void resolveDestroyMethodWithMatchingCandidateReplacedForAutoCloseableExecutorService() { |
|
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(BeanImplementingExecutorServiceAndAutoCloseable.class); |
|
|
|
|
beanDefinition.setDestroyMethodName(AbstractBeanDefinition.INFER_METHOD); |
|
|
|
|
beanDefinition.resolveDestroyMethodIfNecessary(); |
|
|
|
|
assertThat(beanDefinition.getDestroyMethodNames()).containsExactly("close"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void resolveDestroyMethodWithNoCandidateSetDestroyMethodNameToNull() { |
|
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(BeanWithNoDestroyMethod.class); |
|
|
|
|
@ -90,6 +116,25 @@ class RootBeanDefinitionTests {
@@ -90,6 +116,25 @@ class RootBeanDefinitionTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class BeanWithShutdownMethod { |
|
|
|
|
|
|
|
|
|
public void shutdown() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract static class BeanImplementingExecutorService implements ExecutorService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract static class BeanImplementingExecutorServiceAndAutoCloseable implements ExecutorService, AutoCloseable { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void close() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class BeanWithNoDestroyMethod { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|