From a524857bd548dbb3245771a374e9ef609dfae7c0 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 1 Mar 2022 15:22:34 +0100 Subject: [PATCH] Fix init/destroy lifecycle method tests See gh-28083 --- .../Spr3775InitDestroyLifecycleTests.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java b/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java index 8fb07dc306f9..4de6652e65a3 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -155,9 +155,9 @@ public void testJsr250AnnotationsWithCustomPrivateInitDestroyMethods() { DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit1", "customDestroy1"); CustomAnnotatedPrivateInitDestroyBean bean = (CustomAnnotatedPrivateInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN); - assertMethodOrdering("init-methods", Arrays.asList("privateCustomInit1","afterPropertiesSet"), bean.initMethods); + assertMethodOrdering(beanClass, "init-methods", Arrays.asList("@PostConstruct.privateCustomInit1", "afterPropertiesSet"), bean.initMethods); beanFactory.destroySingletons(); - assertMethodOrdering("destroy-methods", Arrays.asList("privateCustomDestroy1","destroy"), bean.destroyMethods); + assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("@PreDestroy.privateCustomDestroy1", "destroy"), bean.destroyMethods); } @Test @@ -166,11 +166,11 @@ public void testJsr250AnnotationsWithCustomSameMethodNames() { DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit1", "customDestroy1"); CustomAnnotatedPrivateSameNameInitDestroyBean bean = (CustomAnnotatedPrivateSameNameInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN); - assertMethodOrdering("init-methods", - Arrays.asList("privateCustomInit1","afterPropertiesSet","sameNameCustomInit1"), bean.initMethods); + assertMethodOrdering(beanClass, "init-methods", + Arrays.asList("@PostConstruct.privateCustomInit1", "@PostConstruct.sameNameCustomInit1", "afterPropertiesSet"), bean.initMethods); beanFactory.destroySingletons(); - assertMethodOrdering("destroy-methods", - Arrays.asList("privateCustomDestroy1","destroy","sameNameCustomDestroy1"), bean.destroyMethods); + assertMethodOrdering(beanClass, "destroy-methods", + Arrays.asList("@PreDestroy.sameNameCustomDestroy1", "@PreDestroy.privateCustomDestroy1", "destroy"), bean.destroyMethods); } @Test @@ -229,28 +229,32 @@ public void customDestroy() throws Exception { } } - public static class CustomAnnotatedPrivateInitDestroyBean extends CustomInitializingDisposableBean{ + public static class CustomAnnotatedPrivateInitDestroyBean extends CustomInitializingDisposableBean { @PostConstruct private void customInit1() throws Exception { - this.initMethods.add("privateCustomInit1"); + this.initMethods.add("@PostConstruct.privateCustomInit1"); } @PreDestroy private void customDestroy1() throws Exception { - this.destroyMethods.add("privateCustomDestroy1"); + this.destroyMethods.add("@PreDestroy.privateCustomDestroy1"); } } public static class CustomAnnotatedPrivateSameNameInitDestroyBean extends CustomAnnotatedPrivateInitDestroyBean { + @PostConstruct + @SuppressWarnings("unused") private void customInit1() throws Exception { - this.initMethods.add("sameNameCustomInit1"); + this.initMethods.add("@PostConstruct.sameNameCustomInit1"); } + @PreDestroy + @SuppressWarnings("unused") private void customDestroy1() throws Exception { - this.destroyMethods.add("sameNameCustomDestroy1"); + this.destroyMethods.add("@PreDestroy.sameNameCustomDestroy1"); } }