Skip to content

Commit af14eea

Browse files
vikeychensbrannen
authored andcommitted
Introduce tests for gh-28083
1 parent f968724 commit af14eea

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ public void testJsr250AnnotationsWithShadowedMethods() {
149149
bean.destroyMethods);
150150
}
151151

152+
@Test
153+
public void testJsr250AnnotationsWithCustomPrivateInitDestroyMethods() {
154+
Class<?> beanClass = CustomAnnotatedPrivateInitDestroyBean.class;
155+
DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit1", "customDestroy1");
156+
CustomAnnotatedPrivateInitDestroyBean bean =
157+
(CustomAnnotatedPrivateInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
158+
assertMethodOrdering("init-methods", Arrays.asList("privateCustomInit1","afterPropertiesSet"), bean.initMethods);
159+
beanFactory.destroySingletons();
160+
assertMethodOrdering("destroy-methods", Arrays.asList("privateCustomDestroy1","destroy"), bean.destroyMethods);
161+
}
162+
163+
@Test
164+
public void testJsr250AnnotationsWithCustomSameMethodNames() {
165+
Class<?> beanClass = CustomAnnotatedPrivateSameNameInitDestroyBean.class;
166+
DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit1", "customDestroy1");
167+
CustomAnnotatedPrivateSameNameInitDestroyBean bean =
168+
(CustomAnnotatedPrivateSameNameInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
169+
assertMethodOrdering("init-methods",
170+
Arrays.asList("privateCustomInit1","afterPropertiesSet","sameNameCustomInit1"), bean.initMethods);
171+
beanFactory.destroySingletons();
172+
assertMethodOrdering("destroy-methods",
173+
Arrays.asList("privateCustomDestroy1","destroy","sameNameCustomDestroy1"), bean.destroyMethods);
174+
}
175+
152176
@Test
153177
public void testAllLifecycleMechanismsAtOnce() {
154178
final Class<?> beanClass = AllInOneBean.class;
@@ -205,6 +229,31 @@ public void customDestroy() throws Exception {
205229
}
206230
}
207231

232+
public static class CustomAnnotatedPrivateInitDestroyBean extends CustomInitializingDisposableBean{
233+
234+
@PostConstruct
235+
private void customInit1() throws Exception {
236+
this.initMethods.add("privateCustomInit1");
237+
}
238+
239+
@PreDestroy
240+
private void customDestroy1() throws Exception {
241+
this.destroyMethods.add("privateCustomDestroy1");
242+
}
243+
244+
}
245+
246+
public static class CustomAnnotatedPrivateSameNameInitDestroyBean extends CustomAnnotatedPrivateInitDestroyBean {
247+
248+
private void customInit1() throws Exception {
249+
this.initMethods.add("sameNameCustomInit1");
250+
}
251+
252+
private void customDestroy1() throws Exception {
253+
this.destroyMethods.add("sameNameCustomDestroy1");
254+
}
255+
256+
}
208257

209258
public static class CustomInitializingDisposableBean extends CustomInitDestroyBean
210259
implements InitializingBean, DisposableBean {

0 commit comments

Comments
 (0)