1717package org .springframework .beans .factory .support ;
1818
1919import java .lang .reflect .Method ;
20+ import java .util .concurrent .ExecutorService ;
2021
2122import org .junit .jupiter .api .Test ;
2223
@@ -59,13 +60,38 @@ void setInstanceDoesNotOverrideResolvedFactoryMethodWithNull() {
5960 }
6061
6162 @ Test
62- void resolveDestroyMethodWithMatchingCandidateReplacedInferredVaue () {
63+ void resolveDestroyMethodWithMatchingCandidateReplacedForCloseMethod () {
6364 RootBeanDefinition beanDefinition = new RootBeanDefinition (BeanWithCloseMethod .class );
6465 beanDefinition .setDestroyMethodName (AbstractBeanDefinition .INFER_METHOD );
6566 beanDefinition .resolveDestroyMethodIfNecessary ();
6667 assertThat (beanDefinition .getDestroyMethodNames ()).containsExactly ("close" );
6768 }
6869
70+ @ Test
71+ void resolveDestroyMethodWithMatchingCandidateReplacedForShutdownMethod () {
72+ RootBeanDefinition beanDefinition = new RootBeanDefinition (BeanWithShutdownMethod .class );
73+ beanDefinition .setDestroyMethodName (AbstractBeanDefinition .INFER_METHOD );
74+ beanDefinition .resolveDestroyMethodIfNecessary ();
75+ assertThat (beanDefinition .getDestroyMethodNames ()).containsExactly ("shutdown" );
76+ }
77+
78+ @ Test
79+ void resolveDestroyMethodWithMatchingCandidateReplacedForExecutorService () {
80+ RootBeanDefinition beanDefinition = new RootBeanDefinition (BeanImplementingExecutorService .class );
81+ beanDefinition .setDestroyMethodName (AbstractBeanDefinition .INFER_METHOD );
82+ beanDefinition .resolveDestroyMethodIfNecessary ();
83+ assertThat (beanDefinition .getDestroyMethodNames ()).containsExactly ("shutdown" );
84+ // even on JDK 19+ where the ExecutorService interface declares a default AutoCloseable implementation
85+ }
86+
87+ @ Test
88+ void resolveDestroyMethodWithMatchingCandidateReplacedForAutoCloseableExecutorService () {
89+ RootBeanDefinition beanDefinition = new RootBeanDefinition (BeanImplementingExecutorServiceAndAutoCloseable .class );
90+ beanDefinition .setDestroyMethodName (AbstractBeanDefinition .INFER_METHOD );
91+ beanDefinition .resolveDestroyMethodIfNecessary ();
92+ assertThat (beanDefinition .getDestroyMethodNames ()).containsExactly ("close" );
93+ }
94+
6995 @ Test
7096 void resolveDestroyMethodWithNoCandidateSetDestroyMethodNameToNull () {
7197 RootBeanDefinition beanDefinition = new RootBeanDefinition (BeanWithNoDestroyMethod .class );
@@ -90,6 +116,25 @@ public void close() {
90116 }
91117
92118
119+ static class BeanWithShutdownMethod {
120+
121+ public void shutdown () {
122+ }
123+ }
124+
125+
126+ abstract static class BeanImplementingExecutorService implements ExecutorService {
127+ }
128+
129+
130+ abstract static class BeanImplementingExecutorServiceAndAutoCloseable implements ExecutorService , AutoCloseable {
131+
132+ @ Override
133+ public void close () {
134+ }
135+ }
136+
137+
93138 static class BeanWithNoDestroyMethod {
94139 }
95140
0 commit comments