Skip to content

Commit a524857

Browse files
committed
Fix init/destroy lifecycle method tests
See gh-28083
1 parent af14eea commit a524857

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -155,9 +155,9 @@ public void testJsr250AnnotationsWithCustomPrivateInitDestroyMethods() {
155155
DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit1", "customDestroy1");
156156
CustomAnnotatedPrivateInitDestroyBean bean =
157157
(CustomAnnotatedPrivateInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
158-
assertMethodOrdering("init-methods", Arrays.asList("privateCustomInit1","afterPropertiesSet"), bean.initMethods);
158+
assertMethodOrdering(beanClass, "init-methods", Arrays.asList("@PostConstruct.privateCustomInit1", "afterPropertiesSet"), bean.initMethods);
159159
beanFactory.destroySingletons();
160-
assertMethodOrdering("destroy-methods", Arrays.asList("privateCustomDestroy1","destroy"), bean.destroyMethods);
160+
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("@PreDestroy.privateCustomDestroy1", "destroy"), bean.destroyMethods);
161161
}
162162

163163
@Test
@@ -166,11 +166,11 @@ public void testJsr250AnnotationsWithCustomSameMethodNames() {
166166
DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit1", "customDestroy1");
167167
CustomAnnotatedPrivateSameNameInitDestroyBean bean =
168168
(CustomAnnotatedPrivateSameNameInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
169-
assertMethodOrdering("init-methods",
170-
Arrays.asList("privateCustomInit1","afterPropertiesSet","sameNameCustomInit1"), bean.initMethods);
169+
assertMethodOrdering(beanClass, "init-methods",
170+
Arrays.asList("@PostConstruct.privateCustomInit1", "@PostConstruct.sameNameCustomInit1", "afterPropertiesSet"), bean.initMethods);
171171
beanFactory.destroySingletons();
172-
assertMethodOrdering("destroy-methods",
173-
Arrays.asList("privateCustomDestroy1","destroy","sameNameCustomDestroy1"), bean.destroyMethods);
172+
assertMethodOrdering(beanClass, "destroy-methods",
173+
Arrays.asList("@PreDestroy.sameNameCustomDestroy1", "@PreDestroy.privateCustomDestroy1", "destroy"), bean.destroyMethods);
174174
}
175175

176176
@Test
@@ -229,28 +229,32 @@ public void customDestroy() throws Exception {
229229
}
230230
}
231231

232-
public static class CustomAnnotatedPrivateInitDestroyBean extends CustomInitializingDisposableBean{
232+
public static class CustomAnnotatedPrivateInitDestroyBean extends CustomInitializingDisposableBean {
233233

234234
@PostConstruct
235235
private void customInit1() throws Exception {
236-
this.initMethods.add("privateCustomInit1");
236+
this.initMethods.add("@PostConstruct.privateCustomInit1");
237237
}
238238

239239
@PreDestroy
240240
private void customDestroy1() throws Exception {
241-
this.destroyMethods.add("privateCustomDestroy1");
241+
this.destroyMethods.add("@PreDestroy.privateCustomDestroy1");
242242
}
243243

244244
}
245245

246246
public static class CustomAnnotatedPrivateSameNameInitDestroyBean extends CustomAnnotatedPrivateInitDestroyBean {
247247

248+
@PostConstruct
249+
@SuppressWarnings("unused")
248250
private void customInit1() throws Exception {
249-
this.initMethods.add("sameNameCustomInit1");
251+
this.initMethods.add("@PostConstruct.sameNameCustomInit1");
250252
}
251253

254+
@PreDestroy
255+
@SuppressWarnings("unused")
252256
private void customDestroy1() throws Exception {
253-
this.destroyMethods.add("sameNameCustomDestroy1");
257+
this.destroyMethods.add("@PreDestroy.sameNameCustomDestroy1");
254258
}
255259

256260
}

0 commit comments

Comments
 (0)