Polishing
This commit is contained in:
@@ -22,6 +22,7 @@ import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.ejb.EJB;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -46,15 +47,26 @@ import org.springframework.jndi.support.SimpleJndiBeanFactory;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link CommonAnnotationBeanPostProcessor} and
|
||||
* {@link InitDestroyAnnotationBeanPostProcessor}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class CommonAnnotationBeanPostProcessorTests {
|
||||
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
bpp.setResourceFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostConstructAndPreDestroy() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
|
||||
void postConstructAndPreDestroy() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
|
||||
|
||||
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
|
||||
@@ -64,10 +76,9 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostConstructAndPreDestroyWithPostProcessor() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
void postConstructAndPreDestroyWithPostProcessor() {
|
||||
bf.addBeanPostProcessor(new InitDestroyBeanPostProcessor());
|
||||
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
|
||||
|
||||
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
|
||||
@@ -77,7 +88,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostConstructAndPreDestroyWithApplicationContextAndPostProcessor() {
|
||||
void postConstructAndPreDestroyWithApplicationContextAndPostProcessor() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.registerBeanDefinition("bpp1", new RootBeanDefinition(InitDestroyBeanPostProcessor.class));
|
||||
ctx.registerBeanDefinition("bpp2", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
|
||||
@@ -91,9 +102,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostConstructAndPreDestroyWithLegacyAnnotations() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
|
||||
void postConstructAndPreDestroyWithLegacyAnnotations() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LegacyAnnotatedInitDestroyBean.class));
|
||||
|
||||
LegacyAnnotatedInitDestroyBean bean = (LegacyAnnotatedInitDestroyBean) bf.getBean("annotatedBean");
|
||||
@@ -103,12 +112,10 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostConstructAndPreDestroyWithManualConfiguration() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
void postConstructAndPreDestroyWithManualConfiguration() {
|
||||
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
|
||||
bpp.setInitAnnotationType(PostConstruct.class);
|
||||
bpp.setDestroyAnnotationType(PreDestroy.class);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
|
||||
|
||||
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
|
||||
@@ -118,9 +125,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostProcessorWithNullBean() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
|
||||
void postProcessorWithNullBean() {
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(NullFactory.class);
|
||||
rbd.setFactoryMethodName("create");
|
||||
bf.registerBeanDefinition("bean", rbd);
|
||||
@@ -130,8 +135,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialization() throws Exception {
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
void serialization() throws Exception {
|
||||
CommonAnnotationBeanPostProcessor bpp2 = SerializationTestUtils.serializeAndDeserialize(bpp);
|
||||
|
||||
AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean();
|
||||
@@ -140,7 +144,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializationWithManualConfiguration() throws Exception {
|
||||
void serializationWithManualConfiguration() throws Exception {
|
||||
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
|
||||
bpp.setInitAnnotationType(PostConstruct.class);
|
||||
bpp.setDestroyAnnotationType(PreDestroy.class);
|
||||
@@ -152,11 +156,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjection() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setResourceFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
void resourceInjection() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));
|
||||
TestBean tb = new TestBean();
|
||||
bf.registerSingleton("testBean", tb);
|
||||
@@ -176,11 +176,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjectionWithPrototypes() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setResourceFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
void resourceInjectionWithPrototypes() {
|
||||
RootBeanDefinition abd = new RootBeanDefinition(ResourceInjectionBean.class);
|
||||
abd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
bf.registerBeanDefinition("annotatedBean", abd);
|
||||
@@ -213,11 +209,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjectionWithLegacyAnnotations() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setResourceFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
void resourceInjectionWithLegacyAnnotations() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LegacyResourceInjectionBean.class));
|
||||
TestBean tb = new TestBean();
|
||||
bf.registerSingleton("testBean", tb);
|
||||
@@ -237,9 +229,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjectionWithResolvableDependencyType() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
void resourceInjectionWithResolvableDependencyType() {
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
RootBeanDefinition abd = new RootBeanDefinition(ExtendedResourceInjectionBean.class);
|
||||
@@ -273,11 +263,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjectionWithDefaultMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
void resourceInjectionWithDefaultMethod() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(DefaultMethodResourceInjectionBean.class));
|
||||
TestBean tb2 = new TestBean();
|
||||
bf.registerSingleton("testBean2", tb2);
|
||||
@@ -293,11 +279,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjectionWithTwoProcessors() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setResourceFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
void resourceInjectionWithTwoProcessors() {
|
||||
CommonAnnotationBeanPostProcessor bpp2 = new CommonAnnotationBeanPostProcessor();
|
||||
bpp2.setResourceFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp2);
|
||||
@@ -318,9 +300,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceInjectionFromJndi() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
void resourceInjectionFromJndi() {
|
||||
SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
|
||||
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
|
||||
TestBean tb = new TestBean();
|
||||
@@ -329,7 +309,6 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
jndiTemplate.addObject("java:comp/env/testBean2", tb2);
|
||||
resourceFactory.setJndiTemplate(jndiTemplate);
|
||||
bpp.setResourceFactory(resourceFactory);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));
|
||||
|
||||
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
|
||||
@@ -343,9 +322,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtendedResourceInjection() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
void extendedResourceInjection() {
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
bf.registerResolvableDependency(BeanFactory.class, bf);
|
||||
@@ -396,9 +373,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtendedResourceInjectionWithOverriding() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
void extendedResourceInjectionWithOverriding() {
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
bf.registerResolvableDependency(BeanFactory.class, bf);
|
||||
@@ -453,9 +428,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtendedEjbInjection() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
void extendedEjbInjection() {
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
bf.registerResolvableDependency(BeanFactory.class, bf);
|
||||
@@ -490,12 +463,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLazyResolutionWithResourceField() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
|
||||
void lazyResolutionWithResourceField() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LazyResourceFieldInjectionBean.class));
|
||||
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
|
||||
|
||||
@@ -508,12 +476,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLazyResolutionWithResourceMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
|
||||
void lazyResolutionWithResourceMethod() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LazyResourceMethodInjectionBean.class));
|
||||
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
|
||||
|
||||
@@ -526,12 +489,7 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLazyResolutionWithCglibProxy() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
|
||||
void lazyResolutionWithCglibProxy() {
|
||||
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LazyResourceCglibInjectionBean.class));
|
||||
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
|
||||
|
||||
@@ -544,10 +502,8 @@ class CommonAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLazyResolutionWithFallbackTypeMatch() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
void lazyResolutionWithFallbackTypeMatch() {
|
||||
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
|
||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user