Explicitly close ApplicationContexts and clean up warnings in tests
This commit also ensures that various test methods actually test something now.
This commit is contained in:
parent
64b64d9ba0
commit
9a5891e6e6
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -37,7 +38,9 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AfterAdviceBindingTests {
|
||||
class AfterAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private AdviceBindingCollaborator mockCollaborator;
|
||||
|
||||
|
@ -47,9 +50,8 @@ public class AfterAdviceBindingTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() throws Exception {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
|
@ -62,39 +64,44 @@ public class AfterAdviceBindingTests {
|
|||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOneIntArg() {
|
||||
void oneIntArg() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntArg(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneObjectArgBindingProxyWithThis() {
|
||||
void oneObjectArgBindingProxyWithThis() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneObjectArgBindingTarget() {
|
||||
void oneObjectArgBindingTarget() {
|
||||
testBeanProxy.getDoctor();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneIntAndOneObjectArgs() {
|
||||
void oneIntAndOneObjectArgs() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeedsJoinPoint() {
|
||||
void needsJoinPoint() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPoint("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeedsJoinPointStaticPart() {
|
||||
void needsJoinPointStaticPart() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -39,7 +40,9 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AfterReturningAdviceBindingTests {
|
||||
class AfterReturningAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private AfterReturningAdviceBindingTestAspect afterAdviceAspect;
|
||||
|
||||
|
@ -51,9 +54,8 @@ public class AfterReturningAdviceBindingTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() throws Exception {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
|
@ -67,58 +69,63 @@ public class AfterReturningAdviceBindingTests {
|
|||
this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOneIntArg() {
|
||||
void oneIntArg() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntArg(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneObjectArg() {
|
||||
void oneObjectArg() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneIntAndOneObjectArgs() {
|
||||
void oneIntAndOneObjectArgs() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeedsJoinPoint() {
|
||||
void needsJoinPoint() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPoint("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeedsJoinPointStaticPart() {
|
||||
void needsJoinPointStaticPart() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningString() {
|
||||
void returningString() {
|
||||
testBeanProxy.setName("adrian");
|
||||
testBeanProxy.getName();
|
||||
verify(mockCollaborator).oneString("adrian");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningObject() {
|
||||
void returningObject() {
|
||||
testBeanProxy.returnsThis();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningBean() {
|
||||
void returningBean() {
|
||||
testBeanProxy.returnsThis();
|
||||
verify(mockCollaborator).oneTestBeanArg(this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningBeanArray() {
|
||||
void returningBeanArray() {
|
||||
this.testBeanTarget.setSpouse(new TestBean());
|
||||
ITestBean[] spouses = this.testBeanTarget.getSpouses();
|
||||
testBeanProxy.getSpouses();
|
||||
|
@ -126,20 +133,20 @@ public class AfterReturningAdviceBindingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNoInvokeWhenReturningParameterTypeDoesNotMatch() {
|
||||
void noInvokeWhenReturningParameterTypeDoesNotMatch() {
|
||||
testBeanProxy.setSpouse(this.testBeanProxy);
|
||||
testBeanProxy.getSpouse();
|
||||
verifyNoInteractions(mockCollaborator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningByType() {
|
||||
void returningByType() {
|
||||
testBeanProxy.returnsThis();
|
||||
verify(mockCollaborator).objectMatchNoArgs();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningPrimitive() {
|
||||
void returningPrimitive() {
|
||||
testBeanProxy.setAge(20);
|
||||
testBeanProxy.haveBirthday();
|
||||
verify(mockCollaborator).oneInt(20);
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -33,7 +34,9 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AfterThrowingAdviceBindingTests {
|
||||
class AfterThrowingAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private ITestBean testBean;
|
||||
|
||||
|
@ -43,9 +46,8 @@ public class AfterThrowingAdviceBindingTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
@ -54,16 +56,21 @@ public class AfterThrowingAdviceBindingTests {
|
|||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleAfterThrowing() throws Throwable {
|
||||
void simpleAfterThrowing() throws Throwable {
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(new Throwable()));
|
||||
verify(mockCollaborator).noArgs();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterThrowingWithBinding() throws Throwable {
|
||||
void afterThrowingWithBinding() throws Throwable {
|
||||
Throwable t = new Throwable();
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(t));
|
||||
|
@ -71,7 +78,7 @@ public class AfterThrowingAdviceBindingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAfterThrowingWithNamedTypeRestriction() throws Throwable {
|
||||
void afterThrowingWithNamedTypeRestriction() throws Throwable {
|
||||
Throwable t = new Throwable();
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(t));
|
||||
|
@ -81,7 +88,7 @@ public class AfterThrowingAdviceBindingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAfterThrowingWithRuntimeExceptionBinding() throws Throwable {
|
||||
void afterThrowingWithRuntimeExceptionBinding() throws Throwable {
|
||||
RuntimeException ex = new RuntimeException();
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(ex));
|
||||
|
@ -89,14 +96,14 @@ public class AfterThrowingAdviceBindingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAfterThrowingWithTypeSpecified() throws Throwable {
|
||||
void afterThrowingWithTypeSpecified() throws Throwable {
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(new Throwable()));
|
||||
verify(mockCollaborator).noArgsOnThrowableMatch();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterThrowingWithRuntimeTypeSpecified() throws Throwable {
|
||||
void afterThrowingWithRuntimeTypeSpecified() throws Throwable {
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(new RuntimeException()));
|
||||
verify(mockCollaborator).noArgsOnRuntimeExceptionMatch();
|
||||
|
|
|
@ -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.
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.aop.aspectj;
|
|||
import java.lang.reflect.Method;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -33,7 +34,9 @@ import org.springframework.lang.Nullable;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectAndAdvicePrecedenceTests {
|
||||
class AspectAndAdvicePrecedenceTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private PrecedenceTestAspect highPrecedenceAspect;
|
||||
|
||||
|
@ -47,9 +50,8 @@ public class AspectAndAdvicePrecedenceTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
|
||||
lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect");
|
||||
highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice");
|
||||
|
@ -57,9 +59,14 @@ public class AspectAndAdvicePrecedenceTests {
|
|||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAdviceOrder() {
|
||||
void testAdviceOrder() {
|
||||
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
|
||||
this.highPrecedenceAspect.setCollaborator(collaborator);
|
||||
this.lowPrecedenceAspect.setCollaborator(collaborator);
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,7 +18,6 @@ package org.springframework.aop.aspectj;
|
|||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
|
@ -31,29 +30,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectJExpressionPointcutAdvisorTests {
|
||||
|
||||
private ITestBean testBean;
|
||||
|
||||
private CallCountingInterceptor interceptor;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
interceptor = (CallCountingInterceptor) ctx.getBean("interceptor");
|
||||
}
|
||||
|
||||
class AspectJExpressionPointcutAdvisorTests {
|
||||
|
||||
@Test
|
||||
public void testPointcutting() {
|
||||
assertThat(interceptor.getCount()).as("Count should be 0").isEqualTo(0);
|
||||
void pointcutting() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
ITestBean testBean = ctx.getBean("testBean", ITestBean.class);
|
||||
CallCountingInterceptor interceptor = ctx.getBean("interceptor", CallCountingInterceptor.class);
|
||||
assertThat(interceptor.getCount()).as("Count").isEqualTo(0);
|
||||
testBean.getSpouses();
|
||||
assertThat(interceptor.getCount()).as("Count should be 1").isEqualTo(1);
|
||||
assertThat(interceptor.getCount()).as("Count").isEqualTo(1);
|
||||
testBean.getSpouse();
|
||||
assertThat(interceptor.getCount()).as("Count should be 1").isEqualTo(1);
|
||||
assertThat(interceptor.getCount()).as("Count").isEqualTo(1);
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,6 +18,8 @@ package org.springframework.aop.aspectj;
|
|||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
|
||||
|
@ -35,7 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class BeanNamePointcutAtAspectTests {
|
||||
class BeanNamePointcutAtAspectTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private ITestBean testBean1;
|
||||
|
||||
|
@ -44,19 +48,24 @@ public class BeanNamePointcutAtAspectTests {
|
|||
private CounterAspect counterAspect;
|
||||
|
||||
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
testBean1 = (ITestBean) ctx.getBean("testBean1");
|
||||
testBean3 = (ITestBean) ctx.getBean("testBean3");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchingBeanName() {
|
||||
void matchingBeanName() {
|
||||
boolean condition = testBean1 instanceof Advised;
|
||||
assertThat(condition).as("Expected a proxy").isTrue();
|
||||
|
||||
|
@ -67,7 +76,7 @@ public class BeanNamePointcutAtAspectTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNonMatchingBeanName() {
|
||||
void nonMatchingBeanName() {
|
||||
boolean condition = testBean3 instanceof Advised;
|
||||
assertThat(condition).as("Didn't expect a proxy").isFalse();
|
||||
|
||||
|
@ -76,7 +85,7 @@ public class BeanNamePointcutAtAspectTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProgrammaticProxyCreation() {
|
||||
void programmaticProxyCreation() {
|
||||
ITestBean testBean = new TestBean();
|
||||
|
||||
AspectJProxyFactory factory = new AspectJProxyFactory();
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -37,7 +38,9 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class BeforeAdviceBindingTests {
|
||||
class BeforeAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private AdviceBindingCollaborator mockCollaborator;
|
||||
|
||||
|
@ -47,9 +50,8 @@ public class BeforeAdviceBindingTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() throws Exception {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
|
||||
|
@ -63,38 +65,43 @@ public class BeforeAdviceBindingTests {
|
|||
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testOneIntArg() {
|
||||
void oneIntArg() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntArg(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneObjectArgBoundToProxyUsingThis() {
|
||||
void oneObjectArgBoundToProxyUsingThis() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneIntAndOneObjectArgs() {
|
||||
void oneIntAndOneObjectArgs() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeedsJoinPoint() {
|
||||
void needsJoinPoint() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPoint("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeedsJoinPointStaticPart() {
|
||||
void needsJoinPointStaticPart() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.aop.aspectj;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -31,7 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class DeclarationOrderIndependenceTests {
|
||||
class DeclarationOrderIndependenceTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private TopsyTurvyAspect aspect;
|
||||
|
||||
|
@ -39,28 +42,32 @@ public class DeclarationOrderIndependenceTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
aspect = (TopsyTurvyAspect) ctx.getBean("topsyTurvyAspect");
|
||||
target = (TopsyTurvyTarget) ctx.getBean("topsyTurvyTarget");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTargetIsSerializable() {
|
||||
void testTargetIsSerializable() {
|
||||
boolean condition = this.target instanceof Serializable;
|
||||
assertThat(condition).as("target bean is serializable").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetIsBeanNameAware() {
|
||||
void testTargetIsBeanNameAware() {
|
||||
boolean condition = this.target instanceof BeanNameAware;
|
||||
assertThat(condition).as("target bean is bean name aware").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeAdviceFiringOk() {
|
||||
void testBeforeAdviceFiringOk() {
|
||||
AspectCollaborator collab = new AspectCollaborator();
|
||||
this.aspect.setCollaborator(collab);
|
||||
this.target.doSomething();
|
||||
|
@ -68,7 +75,7 @@ public class DeclarationOrderIndependenceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAroundAdviceFiringOk() {
|
||||
void testAroundAdviceFiringOk() {
|
||||
AspectCollaborator collab = new AspectCollaborator();
|
||||
this.aspect.setCollaborator(collab);
|
||||
this.target.getX();
|
||||
|
@ -76,7 +83,7 @@ public class DeclarationOrderIndependenceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAfterReturningFiringOk() {
|
||||
void testAfterReturningFiringOk() {
|
||||
AspectCollaborator collab = new AspectCollaborator();
|
||||
this.aspect.setCollaborator(collab);
|
||||
this.target.getX();
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -27,31 +28,35 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class DeclareParentsDelegateRefTests {
|
||||
class DeclareParentsDelegateRefTests {
|
||||
|
||||
protected NoMethodsBean noMethodsBean;
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
protected Counter counter;
|
||||
private NoMethodsBean noMethodsBean;
|
||||
|
||||
private Counter counter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
noMethodsBean = (NoMethodsBean) ctx.getBean("noMethodsBean");
|
||||
counter = (Counter) ctx.getBean("counter");
|
||||
counter.reset();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIntroductionWasMade() {
|
||||
boolean condition = noMethodsBean instanceof ICounter;
|
||||
assertThat(condition).as("Introduction must have been made").isTrue();
|
||||
void introductionWasMade() {
|
||||
assertThat(noMethodsBean).as("Introduction must have been made").isInstanceOf(ICounter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntroductionDelegation() {
|
||||
void introductionDelegation() {
|
||||
((ICounter)noMethodsBean).increment();
|
||||
assertThat(counter.getCount()).as("Delegate's counter should be updated").isEqualTo(1);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.Lockable;
|
||||
|
@ -31,7 +32,9 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class DeclareParentsTests {
|
||||
class DeclareParentsTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private ITestBean testBeanProxy;
|
||||
|
||||
|
@ -39,20 +42,23 @@ public class DeclareParentsTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
introductionObject = ctx.getBean("introduction");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIntroductionWasMade() {
|
||||
void introductionWasMade() {
|
||||
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
|
||||
assertThat(AopUtils.isAopProxy(introductionObject)).as("Introduction should not be proxied").isFalse();
|
||||
boolean condition = testBeanProxy instanceof Lockable;
|
||||
assertThat(condition).as("Introduction must have been made").isTrue();
|
||||
assertThat(testBeanProxy).as("Introduction must have been made").isInstanceOf(Lockable.class);
|
||||
}
|
||||
|
||||
// TODO if you change type pattern from org.springframework.beans..*
|
||||
|
@ -60,7 +66,7 @@ public class DeclareParentsTests {
|
|||
// Perhaps generated advisor bean definition could be made to depend
|
||||
// on the introduction, in which case this would not be a problem.
|
||||
@Test
|
||||
public void testLockingWorks() {
|
||||
void lockingWorks() {
|
||||
Lockable lockable = (Lockable) testBeanProxy;
|
||||
assertThat(lockable.locked()).isFalse();
|
||||
|
||||
|
@ -69,8 +75,7 @@ public class DeclareParentsTests {
|
|||
|
||||
testBeanProxy.setName("");
|
||||
lockable.lock();
|
||||
assertThatIllegalStateException().as("should be locked").isThrownBy(() ->
|
||||
testBeanProxy.setName(" "));
|
||||
assertThatIllegalStateException().as("should be locked").isThrownBy(() -> testBeanProxy.setName(" "));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -28,10 +28,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ImplicitJPArgumentMatchingTests {
|
||||
class ImplicitJPArgumentMatchingTests {
|
||||
|
||||
@Test
|
||||
public void testAspect() {
|
||||
@SuppressWarnings("resource")
|
||||
void testAspect() {
|
||||
// nothing to really test; it is enough if we don't get error while creating app context
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Integration tests for overloaded advice.
|
||||
|
@ -29,32 +29,26 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class OverloadedAdviceTests {
|
||||
class OverloadedAdviceTests {
|
||||
|
||||
@Test
|
||||
public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable cause = ex.getRootCause();
|
||||
boolean condition = cause instanceof IllegalArgumentException;
|
||||
assertThat(condition).as("Should be IllegalArgumentException").isTrue();
|
||||
assertThat(cause.getMessage().contains("invalidAbsoluteTypeName")).as("invalidAbsoluteTypeName should be detected by AJ").isTrue();
|
||||
}
|
||||
@SuppressWarnings("resource")
|
||||
void testExceptionOnConfigParsingWithMismatchedAdviceMethod() {
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()))
|
||||
.havingRootCause()
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.as("invalidAbsoluteTypeName should be detected by AJ").withMessageContaining("invalidAbsoluteTypeName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass());
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable cause = ex.getRootCause();
|
||||
boolean condition = cause instanceof IllegalArgumentException;
|
||||
assertThat(condition).as("Should be IllegalArgumentException").isTrue();
|
||||
assertThat(cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method")).as("Cannot resolve method 'myBeforeAdvice' to a unique method").isTrue();
|
||||
}
|
||||
@SuppressWarnings("resource")
|
||||
void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() {
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass()))
|
||||
.havingRootCause()
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.withMessageContaining("Cannot resolve method 'myBeforeAdvice' to a unique method");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
|
|||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -33,7 +34,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ProceedTests {
|
||||
class ProceedTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private SimpleBean testBean;
|
||||
|
||||
|
@ -43,43 +46,46 @@ public class ProceedTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (SimpleBean) ctx.getBean("testBean");
|
||||
firstTestAspect = (ProceedTestingAspect) ctx.getBean("firstTestAspect");
|
||||
secondTestAspect = (ProceedTestingAspect) ctx.getBean("secondTestAspect");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleProceedWithChangedArgs() {
|
||||
void testSimpleProceedWithChangedArgs() {
|
||||
this.testBean.setName("abc");
|
||||
assertThat(this.testBean.getName()).as("Name changed in around advice").isEqualTo("ABC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArgsIsDefensive() {
|
||||
void testGetArgsIsDefensive() {
|
||||
this.testBean.setAge(5);
|
||||
assertThat(this.testBean.getAge()).as("getArgs is defensive").isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProceedWithArgsInSameAspect() {
|
||||
void testProceedWithArgsInSameAspect() {
|
||||
this.testBean.setMyFloat(1.0F);
|
||||
assertThat(this.testBean.getMyFloat() > 1.9F).as("value changed in around advice").isTrue();
|
||||
assertThat(this.firstTestAspect.getLastBeforeFloatValue() > 1.9F).as("changed value visible to next advice in chain").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProceedWithArgsAcrossAspects() {
|
||||
void testProceedWithArgsAcrossAspects() {
|
||||
this.testBean.setSex("male");
|
||||
assertThat(this.testBean.getSex()).as("value changed in around advice").isEqualTo("MALE");
|
||||
assertThat(this.secondTestAspect.getLastBeforeStringValue()).as("changed value visible to next before advice in chain").isEqualTo("MALE");
|
||||
assertThat(this.secondTestAspect.getLastAroundStringValue()).as("changed value visible to next around advice in chain").isEqualTo("MALE");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -214,4 +220,3 @@ class ProceedTestingAspect implements Ordered {
|
|||
return this.lastBeforeFloatValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
|
@ -16,53 +16,52 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* See SPR-1682.
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class SharedPointcutWithArgsMismatchTests {
|
||||
class SharedPointcutWithArgsMismatchTests {
|
||||
|
||||
private ToBeAdvised toBeAdvised;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
toBeAdvised = (ToBeAdvised) ctx.getBean("toBeAdvised");
|
||||
}
|
||||
private static final List<String> messages = new ArrayList<>();
|
||||
|
||||
|
||||
@Test
|
||||
public void testMismatchedArgBinding() {
|
||||
this.toBeAdvised.foo("Hello");
|
||||
void mismatchedArgBinding() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
ToBeAdvised toBeAdvised = ctx.getBean(ToBeAdvised.class);
|
||||
toBeAdvised.foo("test");
|
||||
assertThat(messages).containsExactly("doBefore(String): test", "foo(String): test");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
static class ToBeAdvised {
|
||||
|
||||
public void foo(String s) {
|
||||
messages.add("foo(String): " + s);
|
||||
}
|
||||
}
|
||||
|
||||
static class MyAspect {
|
||||
|
||||
public void doBefore(int x) {
|
||||
messages.add("doBefore(int): " + x);
|
||||
}
|
||||
|
||||
public void doBefore(String x) {
|
||||
messages.add("doBefore(String): " + x);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ToBeAdvised {
|
||||
|
||||
public void foo(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MyAspect {
|
||||
|
||||
public void doBefore(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
|
||||
public void doBefore(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -30,7 +31,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SubtypeSensitiveMatchingTests {
|
||||
class SubtypeSensitiveMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private NonSerializableFoo nonSerializableBean;
|
||||
|
||||
|
@ -40,31 +43,38 @@ public class SubtypeSensitiveMatchingTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
nonSerializableBean = (NonSerializableFoo) ctx.getBean("testClassA");
|
||||
serializableBean = (SerializableFoo) ctx.getBean("testClassB");
|
||||
bar = (Bar) ctx.getBean("testClassC");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBeansAreProxiedOnStaticMatch() {
|
||||
boolean condition = this.serializableBean instanceof Advised;
|
||||
assertThat(condition).as("bean with serializable type should be proxied").isTrue();
|
||||
void beansAreProxiedOnStaticMatch() {
|
||||
assertThat(this.serializableBean)
|
||||
.as("bean with serializable type should be proxied")
|
||||
.isInstanceOf(Advised.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
|
||||
boolean condition = this.nonSerializableBean instanceof Advised;
|
||||
assertThat(condition).as("bean with non-serializable type should not be proxied").isFalse();
|
||||
void beansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
|
||||
assertThat(this.nonSerializableBean)
|
||||
.as("bean with non-serializable type should not be proxied")
|
||||
.isNotInstanceOf(Advised.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeansThatDoNotMatchBasedOnOtherTestAreProxied() {
|
||||
boolean condition = this.bar instanceof Advised;
|
||||
assertThat(condition).as("bean with args check should be proxied").isTrue();
|
||||
void beansThatDoNotMatchBasedOnOtherTestAreProxied() {
|
||||
assertThat(this.bar)
|
||||
.as("bean with args check should be proxied")
|
||||
.isInstanceOf(Advised.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
|
|||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -32,37 +33,39 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class TargetPointcutSelectionTests {
|
||||
class TargetPointcutSelectionTests {
|
||||
|
||||
public TestInterface testImpl1;
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
public TestInterface testImpl2;
|
||||
private TestInterface testImpl1;
|
||||
|
||||
public TestAspect testAspectForTestImpl1;
|
||||
private TestInterface testImpl2;
|
||||
|
||||
public TestAspect testAspectForAbstractTestImpl;
|
||||
private TestAspect testAspectForTestImpl1;
|
||||
|
||||
public TestInterceptor testInterceptor;
|
||||
private TestAspect testAspectForAbstractTestImpl;
|
||||
|
||||
private TestInterceptor testInterceptor;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testImpl1 = (TestInterface) ctx.getBean("testImpl1");
|
||||
testImpl2 = (TestInterface) ctx.getBean("testImpl2");
|
||||
testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
|
||||
testAspectForAbstractTestImpl = (TestAspect) ctx.getBean("testAspectForAbstractTestImpl");
|
||||
testInterceptor = (TestInterceptor) ctx.getBean("testInterceptor");
|
||||
}
|
||||
|
||||
testAspectForTestImpl1.count = 0;
|
||||
testAspectForAbstractTestImpl.count = 0;
|
||||
testInterceptor.count = 0;
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void targetSelectionForMatchedType() {
|
||||
void targetSelectionForMatchedType() {
|
||||
testImpl1.interfaceMethod();
|
||||
assertThat(testAspectForTestImpl1.count).as("Should have been advised by POJO advice for impl").isEqualTo(1);
|
||||
assertThat(testAspectForAbstractTestImpl.count).as("Should have been advised by POJO advice for base type").isEqualTo(1);
|
||||
|
@ -70,49 +73,43 @@ public class TargetPointcutSelectionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void targetNonSelectionForMismatchedType() {
|
||||
void targetNonSelectionForMismatchedType() {
|
||||
testImpl2.interfaceMethod();
|
||||
assertThat(testAspectForTestImpl1.count).as("Shouldn't have been advised by POJO advice for impl").isEqualTo(0);
|
||||
assertThat(testAspectForTestImpl1.count).as("Shouldn't have been advised by POJO advice for impl").isZero();
|
||||
assertThat(testAspectForAbstractTestImpl.count).as("Should have been advised by POJO advice for base type").isEqualTo(1);
|
||||
assertThat(testInterceptor.count).as("Shouldn't have been advised by advisor").isEqualTo(0);
|
||||
assertThat(testInterceptor.count).as("Shouldn't have been advised by advisor").isZero();
|
||||
}
|
||||
|
||||
|
||||
public static interface TestInterface {
|
||||
|
||||
public void interfaceMethod();
|
||||
interface TestInterface {
|
||||
void interfaceMethod();
|
||||
}
|
||||
|
||||
|
||||
// Reproducing bug requires that the class specified in target() pointcut doesn't
|
||||
// include the advised method's implementation (instead a base class should include it)
|
||||
public static abstract class AbstractTestImpl implements TestInterface {
|
||||
static abstract class AbstractTestImpl implements TestInterface {
|
||||
|
||||
@Override
|
||||
public void interfaceMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class TestImpl1 extends AbstractTestImpl {
|
||||
static class TestImpl1 extends AbstractTestImpl {
|
||||
}
|
||||
|
||||
|
||||
public static class TestImpl2 extends AbstractTestImpl {
|
||||
static class TestImpl2 extends AbstractTestImpl {
|
||||
}
|
||||
|
||||
static class TestAspect {
|
||||
|
||||
public static class TestAspect {
|
||||
int count;
|
||||
|
||||
public int count;
|
||||
|
||||
public void increment() {
|
||||
void increment() {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class TestInterceptor extends TestAspect implements MethodInterceptor {
|
||||
static class TestInterceptor extends TestAspect implements MethodInterceptor {
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
|
|
|
@ -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.
|
||||
|
@ -21,6 +21,8 @@ import java.lang.annotation.RetentionPolicy;
|
|||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
@ -30,8 +32,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private TestInterface testBean;
|
||||
|
||||
|
@ -42,10 +47,9 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
|||
private Counter counter;
|
||||
|
||||
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (TestInterface) ctx.getBean("testBean");
|
||||
testAnnotatedClassBean = (TestInterface) ctx.getBean("testAnnotatedClassBean");
|
||||
testAnnotatedMethodBean = (TestInterface) ctx.getBean("testAnnotatedMethodBean");
|
||||
|
@ -53,58 +57,63 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
|||
counter.reset();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void thisAsClassDoesNotMatch() {
|
||||
void thisAsClassDoesNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsClassCounter).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thisAsInterfaceMatch() {
|
||||
void thisAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetAsClassDoesMatch() {
|
||||
void targetAsClassDoesMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.targetAsClassCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetAsInterfaceMatch() {
|
||||
void targetAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.targetAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsClassAndTargetAsClassCounter).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsInterfaceAndTargetAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsInterfaceAndTargetAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void atTargetClassAnnotationMatch() {
|
||||
void atTargetClassAnnotationMatch() {
|
||||
testAnnotatedClassBean.doIt();
|
||||
assertThat(counter.atTargetClassAnnotationCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atAnnotationMethodAnnotationMatch() {
|
||||
void atAnnotationMethodAnnotationMatch() {
|
||||
testAnnotatedMethodBean.doIt();
|
||||
assertThat(counter.atAnnotationMethodAnnotationCounter).isEqualTo(1);
|
||||
}
|
||||
|
@ -121,7 +130,6 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
|||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public static @interface TestAnnotation {
|
||||
|
||||
}
|
||||
|
||||
@TestAnnotation
|
||||
|
@ -211,4 +219,5 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -26,8 +27,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ThisAndTargetSelectionOnlyPointcutsTests {
|
||||
class ThisAndTargetSelectionOnlyPointcutsTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private TestInterface testBean;
|
||||
|
||||
|
@ -37,70 +41,64 @@ public class ThisAndTargetSelectionOnlyPointcutsTests {
|
|||
private Counter targetAsInterfaceCounter;
|
||||
private Counter thisAsClassAndTargetAsClassCounter;
|
||||
private Counter thisAsInterfaceAndTargetAsInterfaceCounter;
|
||||
private Counter thisAsInterfaceAndTargetAsClassCounter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (TestInterface) ctx.getBean("testBean");
|
||||
thisAsClassCounter = (Counter) ctx.getBean("thisAsClassCounter");
|
||||
thisAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceCounter");
|
||||
targetAsClassCounter = (Counter) ctx.getBean("targetAsClassCounter");
|
||||
targetAsInterfaceCounter = (Counter) ctx.getBean("targetAsInterfaceCounter");
|
||||
thisAsClassAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsClassAndTargetAsClassCounter");
|
||||
thisAsInterfaceAndTargetAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsInterfaceCounter");
|
||||
thisAsInterfaceAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsClassCounter");
|
||||
thisAsClassCounter = ctx.getBean("thisAsClassCounter", Counter.class);
|
||||
thisAsInterfaceCounter = ctx.getBean("thisAsInterfaceCounter", Counter.class);
|
||||
targetAsClassCounter = ctx.getBean("targetAsClassCounter", Counter.class);
|
||||
targetAsInterfaceCounter = ctx.getBean("targetAsInterfaceCounter", Counter.class);
|
||||
thisAsClassAndTargetAsClassCounter = ctx.getBean("thisAsClassAndTargetAsClassCounter", Counter.class);
|
||||
thisAsInterfaceAndTargetAsInterfaceCounter = ctx.getBean("thisAsInterfaceAndTargetAsInterfaceCounter", Counter.class);
|
||||
}
|
||||
|
||||
thisAsClassCounter.reset();
|
||||
thisAsInterfaceCounter.reset();
|
||||
targetAsClassCounter.reset();
|
||||
targetAsInterfaceCounter.reset();
|
||||
thisAsClassAndTargetAsClassCounter.reset();
|
||||
thisAsInterfaceAndTargetAsInterfaceCounter.reset();
|
||||
thisAsInterfaceAndTargetAsClassCounter.reset();
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testThisAsClassDoesNotMatch() {
|
||||
void thisAsClassDoesNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsClassCounter.getCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisAsInterfaceMatch() {
|
||||
void thisAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetAsClassDoesMatch() {
|
||||
void targetAsClassDoesMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(targetAsClassCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetAsInterfaceMatch() {
|
||||
void targetAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(targetAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsClassAndTargetAsClassCounter.getCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsInterfaceAndTargetAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsInterfaceAndTargetAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -27,27 +28,33 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AnnotationBindingTests {
|
||||
class AnnotationBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
void annotationBindingInAroundAdvice() {
|
||||
assertThat(testBean.doThis()).isEqualTo("this value");
|
||||
assertThat(testBean.doThat()).isEqualTo("that value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
void noMatchingWithoutAnnotationPresent() {
|
||||
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj.autoproxy;
|
|||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -29,27 +30,32 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AnnotationPointcutTests {
|
||||
class AnnotationPointcutTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
this.testBean = ctx.getBean("testBean", AnnotatedTestBean.class);
|
||||
}
|
||||
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
void annotationBindingInAroundAdvice() {
|
||||
assertThat(testBean.doThis()).isEqualTo("this value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
void noMatchingWithoutAnnotationPresent() {
|
||||
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -30,21 +30,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class AspectImplementingInterfaceTests {
|
||||
class AspectImplementingInterfaceTests {
|
||||
|
||||
@Test
|
||||
public void testProxyCreation() {
|
||||
void proxyCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
ITestBean testBean = (ITestBean) ctx.getBean("testBean");
|
||||
AnInterface interfaceExtendingAspect = (AnInterface) ctx.getBean("interfaceExtendingAspect");
|
||||
ITestBean testBean = ctx.getBean("testBean", ITestBean.class);
|
||||
AnInterface interfaceExtendingAspect = ctx.getBean("interfaceExtendingAspect", AnInterface.class);
|
||||
|
||||
boolean condition = testBean instanceof Advised;
|
||||
assertThat(condition).isTrue();
|
||||
boolean condition1 = interfaceExtendingAspect instanceof Advised;
|
||||
assertThat(condition1).isFalse();
|
||||
assertThat(testBean).isInstanceOf(Advised.class);
|
||||
assertThat(interfaceExtendingAspect).isNotInstanceOf(Advised.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
||||
class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
||||
|
||||
@Test
|
||||
public void testAdrian() {
|
||||
void testAdrian() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
|
@ -42,6 +42,7 @@ public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
|||
adrian.getAge();
|
||||
assertThat(adrian.getAge()).isEqualTo(68);
|
||||
assertThat(LazyTestBean.instantiations).isEqualTo(1);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 2.0
|
||||
*/
|
||||
public class AtAspectJAfterThrowingTests {
|
||||
class AtAspectJAfterThrowingTests {
|
||||
|
||||
@Test
|
||||
public void testAccessThrowable() {
|
||||
void accessThrowable() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
|
@ -54,6 +54,8 @@ public class AtAspectJAfterThrowingTests {
|
|||
|
||||
assertThat(aspect.handled).isEqualTo(1);
|
||||
assertThat(aspect.lastException).isSameAs(exceptionThrown);
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class BenchmarkTests {
|
||||
class BenchmarkTests {
|
||||
|
||||
private static final Class<?> CLASS = BenchmarkTests.class;
|
||||
|
||||
|
@ -54,42 +54,42 @@ public class BenchmarkTests {
|
|||
private static final String SPRING_AOP_CONTEXT = CLASS.getSimpleName() + "-springAop.xml";
|
||||
|
||||
@Test
|
||||
public void testRepeatedAroundAdviceInvocationsWithAspectJ() {
|
||||
void repeatedAroundAdviceInvocationsWithAspectJ() {
|
||||
testRepeatedAroundAdviceInvocations(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedAroundAdviceInvocationsWithSpringAop() {
|
||||
void repeatedAroundAdviceInvocationsWithSpringAop() {
|
||||
testRepeatedAroundAdviceInvocations(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedBeforeAdviceInvocationsWithAspectJ() {
|
||||
void repeatedBeforeAdviceInvocationsWithAspectJ() {
|
||||
testBeforeAdviceWithoutJoinPoint(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedBeforeAdviceInvocationsWithSpringAop() {
|
||||
void repeatedBeforeAdviceInvocationsWithSpringAop() {
|
||||
testBeforeAdviceWithoutJoinPoint(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedAfterReturningAdviceInvocationsWithAspectJ() {
|
||||
void repeatedAfterReturningAdviceInvocationsWithAspectJ() {
|
||||
testAfterReturningAdviceWithoutJoinPoint(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedAfterReturningAdviceInvocationsWithSpringAop() {
|
||||
void repeatedAfterReturningAdviceInvocationsWithSpringAop() {
|
||||
testAfterReturningAdviceWithoutJoinPoint(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedMixWithAspectJ() {
|
||||
void repeatedMixWithAspectJ() {
|
||||
testMix(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedMixWithSpringAop() {
|
||||
void repeatedMixWithSpringAop() {
|
||||
testMix(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
|
@ -101,11 +101,11 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated around advice invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
assertThat(adrian.getAge()).isEqualTo(68);
|
||||
|
@ -115,16 +115,17 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
sw.stop();
|
||||
System.out.println(sw.prettyPrint());
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated before advice invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
Advised a = (Advised) adrian;
|
||||
|
@ -136,16 +137,17 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
sw.stop();
|
||||
System.out.println(sw.prettyPrint());
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated after returning advice invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
Advised a = (Advised) adrian;
|
||||
|
@ -158,16 +160,17 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
sw.stop();
|
||||
System.out.println(sw.prettyPrint());
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
private long testMix(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated mixed invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
Advised a = (Advised) adrian;
|
||||
|
@ -186,7 +189,8 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
sw.stop();
|
||||
System.out.println(sw.prettyPrint());
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -32,20 +32,19 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SPR3064Tests {
|
||||
|
||||
private Service service;
|
||||
|
||||
class SPR3064Tests {
|
||||
|
||||
@Test
|
||||
public void testServiceIsAdvised() {
|
||||
void testServiceIsAdvised() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
service = (Service) ctx.getBean("service");
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
|
||||
this.service::serveMe)
|
||||
.withMessageContaining("advice invoked");
|
||||
Service service = ctx.getBean(Service.class);
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(service::serveMe)
|
||||
.withMessage("advice invoked");
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -22,6 +22,7 @@ import java.util.Collection;
|
|||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -40,7 +41,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AfterReturningGenericTypeMatchingTests {
|
||||
class AfterReturningGenericTypeMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private GenericReturnTypeVariationClass testBean;
|
||||
|
||||
|
@ -48,9 +51,8 @@ public class AfterReturningGenericTypeMatchingTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.reset();
|
||||
|
@ -58,9 +60,14 @@ public class AfterReturningGenericTypeMatchingTests {
|
|||
testBean = (GenericReturnTypeVariationClass) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReturnTypeExactMatching() {
|
||||
void returnTypeExactMatching() {
|
||||
testBean.getStrings();
|
||||
assertThat(counterAspect.getStringsInvocationsCount).isEqualTo(1);
|
||||
assertThat(counterAspect.getIntegersInvocationsCount).isEqualTo(0);
|
||||
|
@ -73,7 +80,7 @@ public class AfterReturningGenericTypeMatchingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeRawMatching() {
|
||||
void returnTypeRawMatching() {
|
||||
testBean.getStrings();
|
||||
assertThat(counterAspect.getRawsInvocationsCount).isEqualTo(1);
|
||||
|
||||
|
@ -84,13 +91,13 @@ public class AfterReturningGenericTypeMatchingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeUpperBoundMatching() {
|
||||
void returnTypeUpperBoundMatching() {
|
||||
testBean.getIntegers();
|
||||
assertThat(counterAspect.getNumbersInvocationsCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeLowerBoundMatching() {
|
||||
void returnTypeLowerBoundMatching() {
|
||||
testBean.getTestBeans();
|
||||
assertThat(counterAspect.getTestBeanInvocationsCount).isEqualTo(1);
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -25,21 +25,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* <p>This class focuses on class proxying.
|
||||
*
|
||||
* <p>See GenericBridgeMethodMatchingTests for more details.
|
||||
* <p>See {@link GenericBridgeMethodMatchingTests} for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests {
|
||||
class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests {
|
||||
|
||||
@Test
|
||||
public void testGenericDerivedInterfaceMethodThroughClass() {
|
||||
void testGenericDerivedInterfaceMethodThroughClass() {
|
||||
((DerivedStringParameterizedClass) testBean).genericDerivedInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericBaseInterfaceMethodThroughClass() {
|
||||
void testGenericBaseInterfaceMethodThroughClass() {
|
||||
((DerivedStringParameterizedClass) testBean).genericBaseInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,6 +18,8 @@ package org.springframework.aop.aspectj.generic;
|
|||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
@ -39,34 +41,40 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericBridgeMethodMatchingTests {
|
||||
class GenericBridgeMethodMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
protected DerivedInterface<String> testBean;
|
||||
|
||||
protected GenericCounterAspect counterAspect;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
counterAspect = (GenericCounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect = ctx.getBean("counterAspect", GenericCounterAspect.class);
|
||||
counterAspect.count = 0;
|
||||
|
||||
testBean = (DerivedInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenericDerivedInterfaceMethodThroughInterface() {
|
||||
void testGenericDerivedInterfaceMethodThroughInterface() {
|
||||
testBean.genericDerivedInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericBaseInterfaceMethodThroughInterface() {
|
||||
void testGenericBaseInterfaceMethodThroughInterface() {
|
||||
testBean.genericBaseInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
@ -82,7 +90,7 @@ interface BaseInterface<T> {
|
|||
|
||||
interface DerivedInterface<T> extends BaseInterface<T> {
|
||||
|
||||
public void genericDerivedInterfaceMethod(T t);
|
||||
void genericDerivedInterfaceMethod(T t);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -21,6 +21,8 @@ import java.util.Collection;
|
|||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
@ -34,40 +36,44 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericParameterMatchingTests {
|
||||
class GenericParameterMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
private CounterAspect counterAspect;
|
||||
|
||||
private GenericInterface<String> testBean;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.reset();
|
||||
|
||||
testBean = (GenericInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenericInterfaceGenericArgExecution() {
|
||||
void testGenericInterfaceGenericArgExecution() {
|
||||
testBean.save("");
|
||||
assertThat(counterAspect.genericInterfaceGenericArgExecutionCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericInterfaceGenericCollectionArgExecution() {
|
||||
void testGenericInterfaceGenericCollectionArgExecution() {
|
||||
testBean.saveAll(null);
|
||||
assertThat(counterAspect.genericInterfaceGenericCollectionArgExecutionCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericInterfaceSubtypeGenericCollectionArgExecution() {
|
||||
void testGenericInterfaceSubtypeGenericCollectionArgExecution() {
|
||||
testBean.saveAll(null);
|
||||
assertThat(counterAspect.genericInterfaceSubtypeGenericCollectionArgExecutionCount).isEqualTo(1);
|
||||
}
|
||||
|
@ -75,9 +81,9 @@ public class GenericParameterMatchingTests {
|
|||
|
||||
static interface GenericInterface<T> {
|
||||
|
||||
public void save(T bean);
|
||||
void save(T bean);
|
||||
|
||||
public void saveAll(Collection<T> beans);
|
||||
void saveAll(Collection<T> beans);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
public class AopNamespaceHandlerAdviceTypeTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testParsingOfAdviceTypes() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
public class AopNamespaceHandlerArgNamesTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testArgNamesOK() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
public class AopNamespaceHandlerReturningTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testReturningOnReturningAdvice() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
public class AopNamespaceHandlerThrowingTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testThrowingOnThrowingAdvice() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -40,33 +40,34 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @author Dmitriy Kopylenko
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AdvisorAdapterRegistrationTests {
|
||||
class AdvisorAdapterRegistrationTests {
|
||||
|
||||
@BeforeEach
|
||||
@AfterEach
|
||||
public void resetGlobalAdvisorAdapterRegistry() {
|
||||
void resetGlobalAdvisorAdapterRegistry() {
|
||||
GlobalAdvisorAdapterRegistry.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvisorAdapterRegistrationManagerNotPresentInContext() {
|
||||
void advisorAdapterRegistrationManagerNotPresentInContext() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-without-bpp.xml", getClass());
|
||||
ITestBean tb = (ITestBean) ctx.getBean("testBean");
|
||||
// just invoke any method to see if advice fired
|
||||
assertThatExceptionOfType(UnknownAdviceTypeException.class).isThrownBy(
|
||||
tb::getName);
|
||||
assertThatExceptionOfType(UnknownAdviceTypeException.class).isThrownBy(tb::getName);
|
||||
assertThat(getAdviceImpl(tb).getInvocationCounter()).isZero();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvisorAdapterRegistrationManagerPresentInContext() {
|
||||
void advisorAdapterRegistrationManagerPresentInContext() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-with-bpp.xml", getClass());
|
||||
ITestBean tb = (ITestBean) ctx.getBean("testBean");
|
||||
// just invoke any method to see if advice fired
|
||||
tb.getName();
|
||||
getAdviceImpl(tb).getInvocationCounter();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -32,18 +32,23 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class BeanNameAutoProxyCreatorInitTests {
|
||||
class BeanNameAutoProxyCreatorInitTests {
|
||||
|
||||
@Test
|
||||
public void testIgnoreAdvisorThatIsCurrentlyInCreation() {
|
||||
void ignoreAdvisorThatIsCurrentlyInCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
TestBean bean = (TestBean) ctx.getBean("bean");
|
||||
|
||||
TestBean bean = ctx.getBean(TestBean.class);
|
||||
bean.setName("foo");
|
||||
assertThat(bean.getName()).isEqualTo("foo");
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
bean.setName(null));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> bean.setName(null))
|
||||
.withMessage("Null argument at position 0");
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -26,14 +26,13 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BridgeMethodAutowiringTests {
|
||||
class BridgeMethodAutowiringTests {
|
||||
|
||||
@Test
|
||||
public void SPR8434() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(UserServiceImpl.class, Foo.class);
|
||||
ctx.refresh();
|
||||
void SPR8434() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(UserServiceImpl.class, Foo.class);
|
||||
assertThat(ctx.getBean(UserServiceImpl.class).object).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -19,28 +19,31 @@ package org.springframework.beans.factory.xml;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for combining the expression language and the p namespace. Due to the required EL dependency, this test is in
|
||||
* context module rather than the beans module.
|
||||
* Tests for combining the expression language and the p namespace.
|
||||
*
|
||||
* <p>Due to the required EL dependency, this test is in context module rather
|
||||
* than the beans module.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class SimplePropertyNamespaceHandlerWithExpressionLanguageTests {
|
||||
class SimplePropertyNamespaceHandlerWithExpressionLanguageTests {
|
||||
|
||||
@Test
|
||||
public void combineWithExpressionLanguage() {
|
||||
ApplicationContext applicationContext =
|
||||
void combineWithExpressionLanguage() {
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("simplePropertyNamespaceHandlerWithExpressionLanguageTests.xml",
|
||||
getClass());
|
||||
ITestBean foo = applicationContext.getBean("foo", ITestBean.class);
|
||||
ITestBean bar = applicationContext.getBean("bar", ITestBean.class);
|
||||
assertThat(foo.getName()).as("Invalid name").isEqualTo("Baz");
|
||||
assertThat(bar.getName()).as("Invalid name").isEqualTo("Baz");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -53,10 +53,10 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CacheReproTests {
|
||||
class CacheReproTests {
|
||||
|
||||
@Test
|
||||
public void spr11124MultipleAnnotations() {
|
||||
void spr11124MultipleAnnotations() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11124Config.class);
|
||||
Spr11124Service bean = context.getBean(Spr11124Service.class);
|
||||
bean.single(2);
|
||||
|
@ -67,7 +67,7 @@ public class CacheReproTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void spr11249PrimitiveVarargs() {
|
||||
void spr11249PrimitiveVarargs() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11249Config.class);
|
||||
Spr11249Service bean = context.getBean(Spr11249Service.class);
|
||||
Object result = bean.doSomething("op", 2, 3);
|
||||
|
@ -76,7 +76,7 @@ public class CacheReproTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void spr11592GetSimple() {
|
||||
void spr11592GetSimple() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
|
||||
Spr11592Service bean = context.getBean(Spr11592Service.class);
|
||||
Cache cache = context.getBean("cache", Cache.class);
|
||||
|
@ -93,7 +93,7 @@ public class CacheReproTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void spr11592GetNeverCache() {
|
||||
void spr11592GetNeverCache() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
|
||||
Spr11592Service bean = context.getBean(Spr11592Service.class);
|
||||
Cache cache = context.getBean("cache", Cache.class);
|
||||
|
@ -110,7 +110,7 @@ public class CacheReproTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void spr13081ConfigNoCacheNameIsRequired() {
|
||||
void spr13081ConfigNoCacheNameIsRequired() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
|
||||
MyCacheResolver cacheResolver = context.getBean(MyCacheResolver.class);
|
||||
Spr13081Service bean = context.getBean(Spr13081Service.class);
|
||||
|
@ -118,20 +118,21 @@ public class CacheReproTests {
|
|||
assertThat(cacheResolver.getCache("foo").get("foo")).isNull();
|
||||
Object result = bean.getSimple("foo"); // cache name = id
|
||||
assertThat(cacheResolver.getCache("foo").get("foo").get()).isEqualTo(result);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr13081ConfigFailIfCacheResolverReturnsNullCacheName() {
|
||||
void spr13081ConfigFailIfCacheResolverReturnsNullCacheName() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
|
||||
Spr13081Service bean = context.getBean(Spr13081Service.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
bean.getSimple(null))
|
||||
assertThatIllegalStateException().isThrownBy(() -> bean.getSimple(null))
|
||||
.withMessageContaining(MyCacheResolver.class.getName());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr14230AdaptsToOptional() {
|
||||
void spr14230AdaptsToOptional() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr14230Config.class);
|
||||
Spr14230Service bean = context.getBean(Spr14230Service.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
|
@ -145,10 +146,11 @@ public class CacheReproTests {
|
|||
TestBean tb2 = bean.findById("tb1").get();
|
||||
assertThat(tb2).isNotSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb2);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr14853AdaptsToOptionalWithSync() {
|
||||
void spr14853AdaptsToOptionalWithSync() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr14853Config.class);
|
||||
Spr14853Service bean = context.getBean(Spr14853Service.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
|
@ -162,10 +164,11 @@ public class CacheReproTests {
|
|||
TestBean tb2 = bean.findById("tb1").get();
|
||||
assertThat(tb2).isNotSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb2);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr15271FindsOnInterfaceWithInterfaceProxy() {
|
||||
void spr15271FindsOnInterfaceWithInterfaceProxy() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr15271ConfigA.class);
|
||||
Spr15271Interface bean = context.getBean(Spr15271Interface.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
|
@ -174,10 +177,11 @@ public class CacheReproTests {
|
|||
bean.insertItem(tb);
|
||||
assertThat(bean.findById("tb1").get()).isSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr15271FindsOnInterfaceWithCglibProxy() {
|
||||
void spr15271FindsOnInterfaceWithCglibProxy() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr15271ConfigB.class);
|
||||
Spr15271Interface bean = context.getBean(Spr15271Interface.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
|
@ -186,6 +190,7 @@ public class CacheReproTests {
|
|||
bean.insertItem(tb);
|
||||
assertThat(bean.findById("tb1").get()).isSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
/** hook into superclass suite of tests */
|
||||
@Override
|
||||
|
@ -61,26 +61,28 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testKeyStrategy() {
|
||||
void keyStrategy() {
|
||||
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator", KeyGenerator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheErrorHandler() {
|
||||
void cacheErrorHandler() {
|
||||
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleCacheManagerBean() {
|
||||
void singleCacheManagerBean() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(SingleCacheManagerConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleCacheManagerBeans() {
|
||||
void multipleCacheManagerBeans() {
|
||||
@SuppressWarnings("resource")
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(MultiCacheManagerConfig.class);
|
||||
try {
|
||||
|
@ -93,14 +95,16 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void multipleCacheManagerBeans_implementsCachingConfigurer() {
|
||||
void multipleCacheManagerBeans_implementsCachingConfigurer() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(MultiCacheManagerConfigurer.class);
|
||||
ctx.refresh(); // does not throw an exception
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleCachingConfigurers() {
|
||||
void multipleCachingConfigurers() {
|
||||
@SuppressWarnings("resource")
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(MultiCacheManagerConfigurer.class, EnableCachingConfig.class);
|
||||
try {
|
||||
|
@ -112,7 +116,8 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void noCacheManagerBeans() {
|
||||
void noCacheManagerBeans() {
|
||||
@SuppressWarnings("resource")
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EmptyConfig.class);
|
||||
try {
|
||||
|
@ -125,7 +130,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyConfigSupport() {
|
||||
void emptyConfigSupport() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
|
||||
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getCacheResolver()).isNotNull();
|
||||
|
@ -135,7 +140,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bothSetOnlyResolverIsUsed() {
|
||||
void bothSetOnlyResolverIsUsed() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
|
||||
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.cache.interceptor;
|
|||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -47,7 +48,9 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CacheErrorHandlerTests {
|
||||
class CacheErrorHandlerTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
private Cache cache;
|
||||
|
||||
|
@ -58,16 +61,21 @@ public class CacheErrorHandlerTests {
|
|||
private SimpleService simpleService;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
void setup() {
|
||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.cache = context.getBean("mockCache", Cache.class);
|
||||
this.cacheInterceptor = context.getBean(CacheInterceptor.class);
|
||||
this.errorHandler = context.getBean(CacheErrorHandler.class);
|
||||
this.simpleService = context.getBean(SimpleService.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFail() {
|
||||
void getFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
willThrow(exception).given(this.cache).get(0L);
|
||||
|
||||
|
@ -78,7 +86,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getAndPutFail() {
|
||||
void getAndPutFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
willThrow(exception).given(this.cache).get(0L);
|
||||
willThrow(exception).given(this.cache).put(0L, 0L); // Update of the cache will fail as well
|
||||
|
@ -93,7 +101,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getFailProperException() {
|
||||
void getFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
willThrow(exception).given(this.cache).get(0L);
|
||||
|
||||
|
@ -105,7 +113,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void putFail() {
|
||||
void putFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||
willThrow(exception).given(this.cache).put(0L, 0L);
|
||||
|
||||
|
@ -114,7 +122,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void putFailProperException() {
|
||||
void putFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||
willThrow(exception).given(this.cache).put(0L, 0L);
|
||||
|
||||
|
@ -126,7 +134,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void evictFail() {
|
||||
void evictFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).evict(0L);
|
||||
|
||||
|
@ -135,7 +143,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void evictFailProperException() {
|
||||
void evictFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).evict(0L);
|
||||
|
||||
|
@ -147,7 +155,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void clearFail() {
|
||||
void clearFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).clear();
|
||||
|
||||
|
@ -156,7 +164,7 @@ public class CacheErrorHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void clearFailProperException() {
|
||||
void clearFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on clear");
|
||||
willThrow(exception).given(this.cache).clear();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -21,6 +21,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -31,7 +32,7 @@ import org.springframework.cache.annotation.CacheConfig;
|
|||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -51,7 +52,9 @@ import static org.springframework.context.testfixture.cache.CacheTestUtils.asser
|
|||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
*/
|
||||
public class CacheResolverCustomizationTests {
|
||||
class CacheResolverCustomizationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private CacheManager cacheManager;
|
||||
|
||||
|
@ -61,16 +64,21 @@ public class CacheResolverCustomizationTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
void setup() {
|
||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.cacheManager = context.getBean("cacheManager", CacheManager.class);
|
||||
this.anotherCacheManager = context.getBean("anotherCacheManager", CacheManager.class);
|
||||
this.simpleService = context.getBean(SimpleService.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void noCustomization() {
|
||||
void noCustomization() {
|
||||
Cache cache = this.cacheManager.getCache("default");
|
||||
|
||||
Object key = new Object();
|
||||
|
@ -81,7 +89,7 @@ public class CacheResolverCustomizationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customCacheResolver() {
|
||||
void customCacheResolver() {
|
||||
Cache cache = this.cacheManager.getCache("primary");
|
||||
|
||||
Object key = new Object();
|
||||
|
@ -92,7 +100,7 @@ public class CacheResolverCustomizationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customCacheManager() {
|
||||
void customCacheManager() {
|
||||
Cache cache = this.anotherCacheManager.getCache("default");
|
||||
|
||||
Object key = new Object();
|
||||
|
@ -103,7 +111,7 @@ public class CacheResolverCustomizationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void runtimeResolution() {
|
||||
void runtimeResolution() {
|
||||
Cache defaultCache = this.cacheManager.getCache("default");
|
||||
Cache primaryCache = this.cacheManager.getCache("primary");
|
||||
|
||||
|
@ -121,7 +129,7 @@ public class CacheResolverCustomizationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void namedResolution() {
|
||||
void namedResolution() {
|
||||
Cache cache = this.cacheManager.getCache("secondary");
|
||||
|
||||
Object key = new Object();
|
||||
|
@ -132,7 +140,7 @@ public class CacheResolverCustomizationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void noCacheResolved() {
|
||||
void noCacheResolved() {
|
||||
Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.noCacheResolved(new Object()))
|
||||
|
@ -140,7 +148,7 @@ public class CacheResolverCustomizationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void unknownCacheResolver() {
|
||||
void unknownCacheResolver() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
|
||||
this.simpleService.unknownCacheResolver(new Object()))
|
||||
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("unknownCacheResolver"));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -63,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ClassPathScanningCandidateComponentProviderTests {
|
||||
class ClassPathScanningCandidateComponentProviderTests {
|
||||
|
||||
private static final String TEST_BASE_PACKAGE = "example.scannable";
|
||||
private static final String TEST_PROFILE_PACKAGE = "example.profilescan";
|
||||
|
@ -75,7 +75,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void defaultsWithScan() {
|
||||
void defaultsWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -83,7 +83,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void defaultsWithIndex() {
|
||||
void defaultsWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testDefault(provider);
|
||||
|
@ -103,7 +103,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void antStylePackageWithScan() {
|
||||
void antStylePackageWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -111,7 +111,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void antStylePackageWithIndex() {
|
||||
void antStylePackageWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testAntStyle(provider);
|
||||
|
@ -125,7 +125,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bogusPackageWithScan() {
|
||||
void bogusPackageWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -134,7 +134,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bogusPackageWithIndex() {
|
||||
void bogusPackageWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
|
||||
|
@ -142,7 +142,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customFiltersFollowedByResetUseIndex() {
|
||||
void customFiltersFollowedByResetUseIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
|
@ -152,7 +152,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customAnnotationTypeIncludeFilterWithScan() {
|
||||
void customAnnotationTypeIncludeFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -160,7 +160,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customAnnotationTypeIncludeFilterWithIndex() {
|
||||
void customAnnotationTypeIncludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testCustomAnnotationTypeIncludeFilter(provider);
|
||||
|
@ -172,7 +172,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customAssignableTypeIncludeFilterWithScan() {
|
||||
void customAssignableTypeIncludeFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -180,7 +180,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customAssignableTypeIncludeFilterWithIndex() {
|
||||
void customAssignableTypeIncludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testCustomAssignableTypeIncludeFilter(provider);
|
||||
|
@ -198,7 +198,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customSupportedIncludeAndExcludedFilterWithScan() {
|
||||
void customSupportedIncludeAndExcludedFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -206,7 +206,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customSupportedIncludeAndExcludeFilterWithIndex() {
|
||||
void customSupportedIncludeAndExcludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testCustomSupportedIncludeAndExcludeFilter(provider);
|
||||
|
@ -225,7 +225,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customSupportIncludeFilterWithNonIndexedTypeUseScan() {
|
||||
void customSupportIncludeFilterWithNonIndexedTypeUseScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
// This annotation type is not directly annotated with Indexed so we can use
|
||||
|
@ -238,7 +238,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customNotSupportedIncludeFilterUseScan() {
|
||||
void customNotSupportedIncludeFilterUseScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
||||
|
@ -249,7 +249,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void excludeFilterWithScan() {
|
||||
void excludeFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
|
@ -258,7 +258,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void excludeFilterWithIndex() {
|
||||
void excludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*Named.*")));
|
||||
|
@ -276,14 +276,14 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithNoFilters() {
|
||||
void withNoFilters() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
assertThat(candidates.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithComponentAnnotationOnly() {
|
||||
void withComponentAnnotationOnly() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
|
||||
|
@ -300,7 +300,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithAspectAnnotationOnly() {
|
||||
void withAspectAnnotationOnly() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
|
@ -309,7 +309,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithInterfaceType() {
|
||||
void withInterfaceType() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
|
@ -318,7 +318,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithClassType() {
|
||||
void withClassType() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
|
@ -327,7 +327,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithMultipleMatchingFilters() {
|
||||
void withMultipleMatchingFilters() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
|
||||
|
@ -340,7 +340,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testExcludeTakesPrecedence() {
|
||||
void excludeTakesPrecedence() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
|
||||
|
@ -354,14 +354,14 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithNullEnvironment() {
|
||||
void withNullEnvironment() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
|
||||
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInactiveProfile() {
|
||||
void withInactiveProfile() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
ConfigurableEnvironment env = new StandardEnvironment();
|
||||
env.setActiveProfiles("other");
|
||||
|
@ -371,7 +371,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithActiveProfile() {
|
||||
void withActiveProfile() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
ConfigurableEnvironment env = new StandardEnvironment();
|
||||
env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
|
||||
|
@ -381,61 +381,67 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_noProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_noProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_validProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_validProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
|
||||
ctx.register(ProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_validMetaAnnotatedProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_validMetaAnnotatedProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles(DevComponent.PROFILE_NAME);
|
||||
ctx.register(ProfileMetaAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_invalidProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_invalidProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles("other");
|
||||
ctx.register(ProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_invalidMetaAnnotatedProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_invalidMetaAnnotatedProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles("other");
|
||||
ctx.register(ProfileMetaAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_defaultProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_defaultProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setDefaultProfiles(TEST_DEFAULT_PROFILE_NAME);
|
||||
// no active profiles are set
|
||||
ctx.register(DefaultProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(DefaultProfileAnnotatedComponent.BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_defaultAndDevProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_defaultAndDevProfile() {
|
||||
Class<?> beanClass = DefaultAndDevProfileAnnotatedComponent.class;
|
||||
String beanName = DefaultAndDevProfileAnnotatedComponent.BEAN_NAME;
|
||||
{
|
||||
|
@ -445,6 +451,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
|
@ -453,6 +460,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
|
@ -461,11 +469,12 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_metaProfile() {
|
||||
void integrationWithAnnotationConfigApplicationContext_metaProfile() {
|
||||
Class<?> beanClass = MetaProfileAnnotatedComponent.class;
|
||||
String beanName = MetaProfileAnnotatedComponent.BEAN_NAME;
|
||||
{
|
||||
|
@ -475,6 +484,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
|
@ -483,6 +493,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
|
@ -491,11 +502,12 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void componentScanningFindsComponentsAnnotatedWithAnnotationsContainingNestedAnnotations() {
|
||||
void componentScanningFindsComponentsAnnotatedWithAnnotationsContainingNestedAnnotations() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
Set<BeanDefinition> components = provider.findCandidateComponents(AnnotatedComponent.class.getPackage().getName());
|
||||
assertThat(components).hasSize(1);
|
||||
|
@ -539,12 +551,12 @@ public class ClassPathScanningCandidateComponentProviderTests {
|
|||
|
||||
@Profile(TEST_DEFAULT_PROFILE_NAME)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DefaultProfile {
|
||||
@interface DefaultProfile {
|
||||
}
|
||||
|
||||
@Profile("dev")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DevProfile {
|
||||
@interface DevProfile {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
|
@ -31,53 +31,59 @@ import org.springframework.context.annotation.componentscan.simple.SimpleCompone
|
|||
public class ComponentScanAndImportAnnotationInteractionTests {
|
||||
|
||||
@Test
|
||||
public void componentScanOverlapsWithImport() {
|
||||
void componentScanOverlapsWithImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config1.class);
|
||||
ctx.register(Config2.class);
|
||||
ctx.refresh(); // no conflicts found trying to register SimpleComponent
|
||||
ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void componentScanOverlapsWithImportUsingAsm() {
|
||||
void componentScanOverlapsWithImportUsingAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config1", new RootBeanDefinition(Config1.class.getName()));
|
||||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(Config2.class.getName()));
|
||||
ctx.refresh(); // no conflicts found trying to register SimpleComponent
|
||||
ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void componentScanViaImport() {
|
||||
void componentScanViaImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config3.class);
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void componentScanViaImportUsingAsm() {
|
||||
void componentScanViaImportUsingAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config", new RootBeanDefinition(Config3.class.getName()));
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void componentScanViaImportUsingScan() {
|
||||
void componentScanViaImportUsingScan() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.componentscan.importing");
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void circularImportViaComponentScan() {
|
||||
void circularImportViaComponentScan() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config", new RootBeanDefinition(ImportingConfig.class.getName()));
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -25,7 +25,6 @@ import org.springframework.context.annotation.componentscan.level3.Level3Compone
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests ensuring that configuration classes marked with @ComponentScan
|
||||
* may be processed recursively
|
||||
|
@ -33,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ComponentScanAnnotationRecursionTests {
|
||||
class ComponentScanAnnotationRecursionTests {
|
||||
|
||||
@Test
|
||||
public void recursion() {
|
||||
void recursion() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Level1Config.class);
|
||||
ctx.refresh();
|
||||
|
@ -49,14 +48,19 @@ public class ComponentScanAnnotationRecursionTests {
|
|||
// assert that enhancement is working
|
||||
assertThat(ctx.getBean("level1Bean")).isSameAs(ctx.getBean("level1Bean"));
|
||||
assertThat(ctx.getBean("level2Bean")).isSameAs(ctx.getBean("level2Bean"));
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void evenCircularScansAreSupported() {
|
||||
@Test
|
||||
void evenCircularScansAreSupported() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(LeftConfig.class); // left scans right, and right scans left
|
||||
ctx.refresh();
|
||||
ctx.getBean("leftConfig"); // but this is handled gracefully
|
||||
ctx.getBean("rightConfig"); // and beans from both packages are available
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -29,33 +28,35 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ComponentScanParserWithUserDefinedStrategiesTests {
|
||||
class ComponentScanParserWithUserDefinedStrategiesTests {
|
||||
|
||||
@Test
|
||||
public void testCustomBeanNameGenerator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
void customBeanNameGenerator() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/customNameGeneratorTests.xml");
|
||||
assertThat(context.containsBean("testing.fooServiceImpl")).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomScopeMetadataResolver() {
|
||||
void customScopeMetadataResolver() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/customScopeResolverTests.xml");
|
||||
BeanDefinition bd = context.getBeanFactory().getBeanDefinition("fooServiceImpl");
|
||||
assertThat(bd.getScope()).isEqualTo("myCustomScope");
|
||||
assertThat(bd.isSingleton()).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidConstructorBeanNameGenerator() {
|
||||
void invalidConstructorBeanNameGenerator() {
|
||||
assertThatExceptionOfType(BeansException.class).isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/invalidConstructorNameGeneratorTests.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidClassNameScopeMetadataResolver() {
|
||||
void invalidClassNameScopeMetadataResolver() {
|
||||
assertThatExceptionOfType(BeansException.class).isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/invalidClassNameScopeResolverTests.xml"));
|
||||
|
|
|
@ -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.
|
||||
|
@ -24,7 +24,6 @@ import org.springframework.beans.testfixture.beans.TestBean;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests semantics of declaring {@link BeanFactoryPostProcessor}-returning @Bean
|
||||
* methods, specifically as regards static @Bean methods and the avoidance of
|
||||
|
@ -33,25 +32,34 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ConfigurationClassAndBFPPTests {
|
||||
class ConfigurationClassAndBFPPTests {
|
||||
|
||||
@Test
|
||||
public void autowiringFailsWithBFPPAsInstanceMethod() {
|
||||
void autowiringFailsWithBFPPAsInstanceMethod() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(TestBeanConfig.class, AutowiredConfigWithBFPPAsInstanceMethod.class);
|
||||
ctx.refresh();
|
||||
// instance method BFPP interferes with lifecycle -> autowiring fails!
|
||||
// WARN-level logging should have been issued about returning BFPP from non-static @Bean method
|
||||
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsInstanceMethod.class).autowiredTestBean).isNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autowiringSucceedsWithBFPPAsStaticMethod() {
|
||||
void autowiringSucceedsWithBFPPAsStaticMethod() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(TestBeanConfig.class, AutowiredConfigWithBFPPAsStaticMethod.class);
|
||||
ctx.refresh();
|
||||
// static method BFPP does not interfere with lifecycle -> autowiring succeeds
|
||||
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsStaticMethod.class).autowiredTestBean).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void staticBeanMethodsDoNotRespectScoping() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithStaticBeanMethod.class);
|
||||
assertThat(ConfigWithStaticBeanMethod.testBean()).isNotSameAs(ConfigWithStaticBeanMethod.testBean());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,7 +71,6 @@ public class ConfigurationClassAndBFPPTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class AutowiredConfigWithBFPPAsInstanceMethod {
|
||||
@Autowired TestBean autowiredTestBean;
|
||||
|
@ -76,7 +83,6 @@ public class ConfigurationClassAndBFPPTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class AutowiredConfigWithBFPPAsStaticMethod {
|
||||
@Autowired TestBean autowiredTestBean;
|
||||
|
@ -89,16 +95,6 @@ public class ConfigurationClassAndBFPPTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void staticBeanMethodsDoNotRespectScoping() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithStaticBeanMethod.class);
|
||||
ctx.refresh();
|
||||
assertThat(ConfigWithStaticBeanMethod.testBean()).isNotSameAs(ConfigWithStaticBeanMethod.testBean());
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class ConfigWithStaticBeanMethod {
|
||||
@Bean
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -54,7 +54,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
@ -389,6 +389,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
.withMessageContaining("alias 'taskExecutor'")
|
||||
.withMessageContaining("name 'applicationTaskExecutor'")
|
||||
.withMessageContaining("bean definition 'taskExecutor'");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -998,118 +999,129 @@ class ConfigurationClassPostProcessorTests {
|
|||
|
||||
@Test
|
||||
void testPrototypeArgumentThroughBeanMethodCall() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithPrototype.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithPrototype.class);
|
||||
ctx.getBean(FooFactory.class).createFoo(new BarArgument());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSingletonArgumentThroughBeanMethodCall() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithSingleton.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithSingleton.class);
|
||||
ctx.getBean(FooFactory.class).createFoo(new BarArgument());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullArgumentThroughBeanMethodCall() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithNull.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithNull.class);
|
||||
ctx.getBean("aFoo");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInjectionPointMatchForNarrowTargetReturnType() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
|
||||
assertThat(ctx.getBean(FooImpl.class).bar).isSameAs(ctx.getBean(BarImpl.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVarargOnBeanMethod() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class);
|
||||
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.length).isEqualTo(1);
|
||||
assertThat(bean.testBeans[0]).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyVarargOnBeanMethod() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class);
|
||||
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.length).isEqualTo(0);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCollectionArgumentOnBeanMethod() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyCollectionArgumentOnBeanMethod() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.isEmpty()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMapArgumentOnBeanMethod() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.values().iterator().next()).isSameAs(ctx.getBean(Runnable.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyMapArgumentOnBeanMethod() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.isEmpty()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCollectionInjectionFromSameConfigurationClass() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
|
||||
CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMapInjectionFromSameConfigurationClass() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
|
||||
MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.get("testBean")).isSameAs(ctx.getBean(Runnable.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanLookupFromSameConfigurationClass() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
|
||||
BeanLookupConfiguration bean = ctx.getBean(BeanLookupConfiguration.class);
|
||||
assertThat(bean.getTestBean()).isNotNull();
|
||||
assertThat(bean.getTestBean()).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNameClashBetweenConfigurationClassAndBean() {
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MyTestBean.class);
|
||||
ctx.getBean("myTestBean", TestBean.class);
|
||||
});
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class)
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class).getBean("myTestBean", TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanDefinitionRegistryPostProcessorConfig() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
|
||||
boolean condition = ctx.getBean("myTestBean") instanceof TestBean;
|
||||
assertThat(condition).isTrue();
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
|
||||
assertThat(ctx.getBean("myTestBean")).isInstanceOf(TestBean.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -32,63 +32,70 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ConfigurationWithFactoryBeanAndAutowiringTests {
|
||||
class ConfigurationWithFactoryBeanAndAutowiringTests {
|
||||
|
||||
@Test
|
||||
public void withConcreteFactoryBeanImplementationAsReturnType() {
|
||||
void withConcreteFactoryBeanImplementationAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(ConcreteFactoryBeanImplementationConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withParameterizedFactoryBeanImplementationAsReturnType() {
|
||||
void withParameterizedFactoryBeanImplementationAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(ParameterizedFactoryBeanImplementationConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
void withParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(ParameterizedFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNonPublicParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
void withNonPublicParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(NonPublicParameterizedFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withRawFactoryBeanInterfaceAsReturnType() {
|
||||
void withRawFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(RawFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withWildcardParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
void withWildcardParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(WildcardParameterizedFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withFactoryBeanCallingBean() {
|
||||
void withFactoryBeanCallingBean() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(FactoryBeanCallingConfig.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean("myString")).isEqualTo("true");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -33,12 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
|
||||
void test() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
|
||||
assertThat(ctx.getBean(Bar.class).foo).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,11 +52,9 @@ public class ConfigurationWithFactoryBeanAndParametersTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
|
||||
static class Bar {
|
||||
|
||||
Foo foo;
|
||||
|
@ -66,7 +65,6 @@ public class ConfigurationWithFactoryBeanAndParametersTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static class FooFactoryBean implements FactoryBean<Foo> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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.
|
||||
|
@ -38,30 +38,33 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class EnableAspectJAutoProxyTests {
|
||||
class EnableAspectJAutoProxyTests {
|
||||
|
||||
@Test
|
||||
public void withJdkProxy() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithJdkProxy.class);
|
||||
void withJdkProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithJdkProxy.class);
|
||||
|
||||
aspectIsApplied(ctx);
|
||||
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class))).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withCglibProxy() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithCglibProxy.class);
|
||||
void withCglibProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithCglibProxy.class);
|
||||
|
||||
aspectIsApplied(ctx);
|
||||
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooService.class))).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withExposedProxy() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExposedProxy.class);
|
||||
void withExposedProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExposedProxy.class);
|
||||
|
||||
aspectIsApplied(ctx);
|
||||
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class))).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private void aspectIsApplied(ApplicationContext ctx) {
|
||||
|
@ -82,7 +85,7 @@ public class EnableAspectJAutoProxyTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void withAnnotationOnArgumentAndJdkProxy() {
|
||||
void withAnnotationOnArgumentAndJdkProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||
ConfigWithJdkProxy.class, SampleService.class, LoggingAspect.class);
|
||||
|
||||
|
@ -91,10 +94,11 @@ public class EnableAspectJAutoProxyTests {
|
|||
sampleService.execute(new SampleInputBean());
|
||||
sampleService.execute((SampleDto) null);
|
||||
sampleService.execute((SampleInputBean) null);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withAnnotationOnArgumentAndCglibProxy() {
|
||||
void withAnnotationOnArgumentAndCglibProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||
ConfigWithCglibProxy.class, SampleService.class, LoggingAspect.class);
|
||||
|
||||
|
@ -103,6 +107,7 @@ public class EnableAspectJAutoProxyTests {
|
|||
sampleService.execute(new SampleInputBean());
|
||||
sampleService.execute((SampleDto) null);
|
||||
sampleService.execute((SampleInputBean) null);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,7 +128,7 @@ public class EnableAspectJAutoProxyTests {
|
|||
static class ConfigWithExposedProxy {
|
||||
|
||||
@Bean
|
||||
public FooService fooServiceImpl(final ApplicationContext context) {
|
||||
FooService fooServiceImpl(final ApplicationContext context) {
|
||||
return new FooServiceImpl() {
|
||||
@Override
|
||||
public String foo(int id) {
|
||||
|
@ -140,20 +145,20 @@ public class EnableAspectJAutoProxyTests {
|
|||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Loggable {
|
||||
@interface Loggable {
|
||||
}
|
||||
|
||||
|
||||
@Loggable
|
||||
public static class SampleDto {
|
||||
static class SampleDto {
|
||||
}
|
||||
|
||||
|
||||
public static class SampleInputBean {
|
||||
static class SampleInputBean {
|
||||
}
|
||||
|
||||
|
||||
public static class SampleService {
|
||||
static class SampleService {
|
||||
|
||||
// Not matched method on {@link LoggingAspect}.
|
||||
public void execute(SampleInputBean inputBean) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -35,26 +35,28 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class EnableLoadTimeWeavingTests {
|
||||
class EnableLoadTimeWeavingTests {
|
||||
|
||||
@Test
|
||||
public void control() {
|
||||
void control() {
|
||||
GenericXmlApplicationContext ctx =
|
||||
new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
|
||||
ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableLTW_withAjWeavingDisabled() {
|
||||
void enableLTW_withAjWeavingDisabled() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
|
||||
ctx.refresh();
|
||||
LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
|
||||
verifyNoInteractions(loadTimeWeaver);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableLTW_withAjWeavingAutodetect() {
|
||||
void enableLTW_withAjWeavingAutodetect() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
|
||||
ctx.refresh();
|
||||
|
@ -62,15 +64,17 @@ public class EnableLoadTimeWeavingTests {
|
|||
// no expectations -> a class file transformer should NOT be added
|
||||
// because no META-INF/aop.xml is present on the classpath
|
||||
verifyNoInteractions(loadTimeWeaver);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableLTW_withAjWeavingEnabled() {
|
||||
void enableLTW_withAjWeavingEnabled() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
|
||||
ctx.refresh();
|
||||
LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
|
||||
verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -39,17 +39,18 @@ import org.springframework.util.Assert;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests that an ImportAware @Configuration classes gets injected with the
|
||||
* Tests that an ImportAware @Configuration class gets injected with the
|
||||
* annotation metadata of the @Configuration class that imported it.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ImportAwareTests {
|
||||
class ImportAwareTests {
|
||||
|
||||
@Test
|
||||
public void directlyAnnotatedWithImport() {
|
||||
@SuppressWarnings("resource")
|
||||
void directlyAnnotatedWithImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingConfig.class);
|
||||
ctx.refresh();
|
||||
|
@ -65,7 +66,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void indirectlyAnnotatedWithImport() {
|
||||
@SuppressWarnings("resource")
|
||||
void indirectlyAnnotatedWithImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(IndirectlyImportingConfig.class);
|
||||
ctx.refresh();
|
||||
|
@ -81,7 +83,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void directlyAnnotatedWithImportLite() {
|
||||
@SuppressWarnings("resource")
|
||||
void directlyAnnotatedWithImportLite() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingConfigLite.class);
|
||||
ctx.refresh();
|
||||
|
@ -97,7 +100,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void importRegistrar() {
|
||||
@SuppressWarnings("resource")
|
||||
void importRegistrar() {
|
||||
ImportedRegistrar.called = false;
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingRegistrarConfig.class);
|
||||
|
@ -107,7 +111,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void importRegistrarWithImport() {
|
||||
@SuppressWarnings("resource")
|
||||
void importRegistrarWithImport() {
|
||||
ImportedRegistrar.called = false;
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingRegistrarConfigWithImport.class);
|
||||
|
@ -119,7 +124,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void metadataFromImportsOneThenTwo() {
|
||||
@SuppressWarnings("resource")
|
||||
void metadataFromImportsOneThenTwo() {
|
||||
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
|
||||
ConfigurationOne.class, ConfigurationTwo.class)
|
||||
.getBean(MetadataHolder.class).importMetadata;
|
||||
|
@ -127,7 +133,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void metadataFromImportsTwoThenOne() {
|
||||
@SuppressWarnings("resource")
|
||||
void metadataFromImportsTwoThenOne() {
|
||||
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
|
||||
ConfigurationTwo.class, ConfigurationOne.class)
|
||||
.getBean(MetadataHolder.class).importMetadata;
|
||||
|
@ -135,7 +142,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void metadataFromImportsOneThenThree() {
|
||||
@SuppressWarnings("resource")
|
||||
void metadataFromImportsOneThenThree() {
|
||||
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
|
||||
ConfigurationOne.class, ConfigurationThree.class)
|
||||
.getBean(MetadataHolder.class).importMetadata;
|
||||
|
@ -143,7 +151,8 @@ public class ImportAwareTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void importAwareWithAnnotationAttributes() {
|
||||
@SuppressWarnings("resource")
|
||||
void importAwareWithAnnotationAttributes() {
|
||||
new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -37,17 +37,16 @@ import org.springframework.core.type.AnnotationMetadata;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ImportBeanDefinitionRegistrar}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ImportBeanDefinitionRegistrarTests {
|
||||
class ImportBeanDefinitionRegistrarTests {
|
||||
|
||||
@Test
|
||||
public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
|
||||
void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
context.getBean(MessageSource.class);
|
||||
|
||||
|
@ -55,6 +54,7 @@ public class ImportBeanDefinitionRegistrarTests {
|
|||
assertThat(SampleRegistrar.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());
|
||||
assertThat(SampleRegistrar.resourceLoader).isNotNull();
|
||||
assertThat(SampleRegistrar.environment).isEqualTo(context.getEnvironment());
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @author Juergen Hoeller
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
|
||||
private void doTestLazyResourceInjection(Class<? extends TestBeanHolder> annotatedBeanClass) {
|
||||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
|
||||
|
@ -63,10 +63,11 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
|
|||
|
||||
assertThat(ObjectUtils.containsElement(bf.getDependenciesForBean("annotatedBean"), "testBean")).isTrue();
|
||||
assertThat(ObjectUtils.containsElement(bf.getDependentBeans("testBean"), "annotatedBean")).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithField() {
|
||||
void lazyResourceInjectionWithField() {
|
||||
doTestLazyResourceInjection(FieldResourceInjectionBean.class);
|
||||
|
||||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
|
||||
|
@ -86,45 +87,46 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
|
|||
TestBean tb = (TestBean) ac.getBean("testBean");
|
||||
tb.setName("tb");
|
||||
assertThat(bean.getTestBean().getName()).isSameAs("tb");
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithFieldAndCustomAnnotation() {
|
||||
void lazyResourceInjectionWithFieldAndCustomAnnotation() {
|
||||
doTestLazyResourceInjection(FieldResourceInjectionBeanWithCompositeAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithMethod() {
|
||||
void lazyResourceInjectionWithMethod() {
|
||||
doTestLazyResourceInjection(MethodResourceInjectionBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithMethodLevelLazy() {
|
||||
void lazyResourceInjectionWithMethodLevelLazy() {
|
||||
doTestLazyResourceInjection(MethodResourceInjectionBeanWithMethodLevelLazy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithMethodAndCustomAnnotation() {
|
||||
void lazyResourceInjectionWithMethodAndCustomAnnotation() {
|
||||
doTestLazyResourceInjection(MethodResourceInjectionBeanWithCompositeAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithConstructor() {
|
||||
void lazyResourceInjectionWithConstructor() {
|
||||
doTestLazyResourceInjection(ConstructorResourceInjectionBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithConstructorLevelLazy() {
|
||||
void lazyResourceInjectionWithConstructorLevelLazy() {
|
||||
doTestLazyResourceInjection(ConstructorResourceInjectionBeanWithConstructorLevelLazy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithConstructorAndCustomAnnotation() {
|
||||
void lazyResourceInjectionWithConstructorAndCustomAnnotation() {
|
||||
doTestLazyResourceInjection(ConstructorResourceInjectionBeanWithCompositeAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyResourceInjectionWithNonExistingTarget() {
|
||||
void lazyResourceInjectionWithNonExistingTarget() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
|
||||
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
|
||||
|
@ -141,7 +143,7 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLazyOptionalResourceInjectionWithNonExistingTarget() {
|
||||
void lazyOptionalResourceInjectionWithNonExistingTarget() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
|
||||
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
|
||||
|
|
|
@ -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.
|
||||
|
@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public class NestedConfigurationClassTests {
|
||||
class NestedConfigurationClassTests {
|
||||
|
||||
@Test
|
||||
public void oneLevelDeep() {
|
||||
void oneLevelDeep() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0Config.L1Config.class);
|
||||
ctx.refresh();
|
||||
|
@ -49,10 +49,11 @@ public class NestedConfigurationClassTests {
|
|||
|
||||
// ensure that override order is correct
|
||||
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l1");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsDeep() {
|
||||
void twoLevelsDeep() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0Config.class);
|
||||
ctx.refresh();
|
||||
|
@ -71,10 +72,11 @@ public class NestedConfigurationClassTests {
|
|||
|
||||
// ensure that override order is correct
|
||||
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l0");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsInLiteMode() {
|
||||
void twoLevelsInLiteMode() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0ConfigLight.class);
|
||||
ctx.refresh();
|
||||
|
@ -93,10 +95,11 @@ public class NestedConfigurationClassTests {
|
|||
|
||||
// ensure that override order is correct
|
||||
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l0");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsDeepWithInheritance() {
|
||||
void twoLevelsDeepWithInheritance() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(S1Config.class);
|
||||
ctx.refresh();
|
||||
|
@ -121,10 +124,11 @@ public class NestedConfigurationClassTests {
|
|||
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
|
||||
assertThat(pb1 != pb2).isTrue();
|
||||
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsDeepWithInheritanceThroughImport() {
|
||||
void twoLevelsDeepWithInheritanceThroughImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(S1Importer.class);
|
||||
ctx.refresh();
|
||||
|
@ -149,10 +153,11 @@ public class NestedConfigurationClassTests {
|
|||
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
|
||||
assertThat(pb1 != pb2).isTrue();
|
||||
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsDeepWithInheritanceAndScopedProxy() {
|
||||
void twoLevelsDeepWithInheritanceAndScopedProxy() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(S1ImporterWithProxy.class);
|
||||
ctx.refresh();
|
||||
|
@ -177,10 +182,11 @@ public class NestedConfigurationClassTests {
|
|||
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
|
||||
assertThat(pb1 != pb2).isTrue();
|
||||
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsWithNoBeanMethods() {
|
||||
void twoLevelsWithNoBeanMethods() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0ConfigEmpty.class);
|
||||
ctx.refresh();
|
||||
|
@ -198,10 +204,11 @@ public class NestedConfigurationClassTests {
|
|||
Object l2i2 = ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.L2ConfigEmpty.class);
|
||||
assertThat(l2i1 == l2i2).isTrue();
|
||||
assertThat(l2i2.toString()).isNotEqualTo(l2i1.toString());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLevelsOnNonAnnotatedBaseClass() {
|
||||
void twoLevelsOnNonAnnotatedBaseClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0ConfigConcrete.class);
|
||||
ctx.refresh();
|
||||
|
@ -219,6 +226,7 @@ public class NestedConfigurationClassTests {
|
|||
Object l2i2 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.L2ConfigEmpty.class);
|
||||
assertThat(l2i1 == l2i2).isTrue();
|
||||
assertThat(l2i2.toString()).isNotEqualTo(l2i1.toString());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import javax.annotation.Resource;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -41,65 +41,64 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class PrimitiveBeanLookupAndAutowiringTests {
|
||||
class PrimitiveBeanLookupAndAutowiringTests {
|
||||
|
||||
@Test
|
||||
public void primitiveLookupByName() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
boolean b = ctx.getBean("b", boolean.class);
|
||||
assertThat(b).isTrue();
|
||||
int i = ctx.getBean("i", int.class);
|
||||
assertThat(i).isEqualTo(42);
|
||||
void primitiveLookupByName() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(ctx.getBean("b", boolean.class)).isTrue();
|
||||
assertThat(ctx.getBean("i", int.class)).isEqualTo(42);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void primitiveLookupByType() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
boolean b = ctx.getBean(boolean.class);
|
||||
assertThat(b).isTrue();
|
||||
int i = ctx.getBean(int.class);
|
||||
assertThat(i).isEqualTo(42);
|
||||
void primitiveLookupByType() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(ctx.getBean(boolean.class)).isTrue();
|
||||
assertThat(ctx.getBean(int.class)).isEqualTo(42);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void primitiveAutowiredInjection() {
|
||||
ApplicationContext ctx =
|
||||
void primitiveAutowiredInjection() {
|
||||
ConfigurableApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Config.class, AutowiredComponent.class);
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).b).isTrue();
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).i).isEqualTo(42);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void primitiveResourceInjection() {
|
||||
ApplicationContext ctx =
|
||||
void primitiveResourceInjection() {
|
||||
ConfigurableApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Config.class, ResourceComponent.class);
|
||||
assertThat(ctx.getBean(ResourceComponent.class).b).isTrue();
|
||||
assertThat(ctx.getBean(ResourceComponent.class).i).isEqualTo(42);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
public boolean b() {
|
||||
boolean b() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public int i() {
|
||||
int i() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class AutowiredComponent {
|
||||
@Autowired boolean b;
|
||||
@Autowired int i;
|
||||
}
|
||||
|
||||
|
||||
static class ResourceComponent {
|
||||
@Resource boolean b;
|
||||
@Autowired int i;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ class PropertySourceAnnotationTests {
|
|||
while (iterator.hasNext());
|
||||
|
||||
assertThat(name).isEqualTo("p1");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,6 +81,7 @@ class PropertySourceAnnotationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithImplicitName.class);
|
||||
assertThat(ctx.getEnvironment().getPropertySources().contains("class path resource [org/springframework/context/annotation/p1.properties]")).as("property source p1 was not added").isTrue();
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,6 +89,7 @@ class PropertySourceAnnotationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithTestProfileBeans.class);
|
||||
assertThat(ctx.containsBean("testBean")).isTrue();
|
||||
assertThat(ctx.containsBean("testProfileBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,6 +104,7 @@ class PropertySourceAnnotationTests {
|
|||
ctx.refresh();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -109,6 +113,7 @@ class PropertySourceAnnotationTests {
|
|||
ctx.refresh();
|
||||
// p1 should 'win' as it was registered last
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +123,7 @@ class PropertySourceAnnotationTests {
|
|||
ctx.register(ConfigWithImplicitName.class, WithCustomFactory.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("P2TESTBEAN");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -126,6 +132,7 @@ class PropertySourceAnnotationTests {
|
|||
ctx.register(ConfigWithImplicitName.class, WithCustomFactoryAsMeta.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("P2TESTBEAN");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -139,6 +146,7 @@ class PropertySourceAnnotationTests {
|
|||
void withUnresolvablePlaceholderAndDefault() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithUnresolvablePlaceholderAndDefault.class);
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -147,6 +155,7 @@ class PropertySourceAnnotationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithResolvablePlaceholder.class);
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
System.clearProperty("path.to.properties");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -155,6 +164,7 @@ class PropertySourceAnnotationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithResolvablePlaceholderAndFactoryBean.class);
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
System.clearProperty("path.to.properties");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -171,6 +181,7 @@ class PropertySourceAnnotationTests {
|
|||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -180,6 +191,7 @@ class PropertySourceAnnotationTests {
|
|||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -189,6 +201,7 @@ class PropertySourceAnnotationTests {
|
|||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -234,6 +247,7 @@ class PropertySourceAnnotationTests {
|
|||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -248,6 +262,7 @@ class PropertySourceAnnotationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithIgnoredPropertySource.class);
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -256,6 +271,7 @@ class PropertySourceAnnotationTests {
|
|||
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -265,6 +281,8 @@ class PropertySourceAnnotationTests {
|
|||
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class);
|
||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctxWithName.close();
|
||||
ctxWithoutName.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -272,6 +290,7 @@ class PropertySourceAnnotationTests {
|
|||
// SPR-12198: p4 should 'win' as it was registered last
|
||||
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithFourResourceLocations.class);
|
||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("p4TestBean");
|
||||
ctxWithoutName.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -283,7 +302,7 @@ class PropertySourceAnnotationTests {
|
|||
ctxWithoutName.register(ConfigWithFourResourceLocations.class);
|
||||
ctxWithoutName.refresh();
|
||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("myTestBean");
|
||||
|
||||
ctxWithoutName.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -24,7 +24,6 @@ import org.springframework.context.annotation.role.ComponentWithoutRole;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the use of the @Role and @Description annotation on @Bean methods and @Component classes.
|
||||
*
|
||||
|
@ -32,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public class RoleAndDescriptionAnnotationTests {
|
||||
class RoleAndDescriptionAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void onBeanMethod() {
|
||||
void onBeanMethod() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config.class);
|
||||
ctx.refresh();
|
||||
|
@ -43,10 +42,11 @@ public class RoleAndDescriptionAnnotationTests {
|
|||
assertThat(ctx.getBeanDefinition("foo").getDescription()).isNull();
|
||||
assertThat(ctx.getBeanDefinition("bar").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
assertThat(ctx.getBeanDefinition("bar").getDescription()).isEqualTo("A Bean method with a role");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onComponentClass() {
|
||||
void onComponentClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ComponentWithoutRole.class, ComponentWithRole.class);
|
||||
ctx.refresh();
|
||||
|
@ -54,11 +54,11 @@ public class RoleAndDescriptionAnnotationTests {
|
|||
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription()).isNull();
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription()).isEqualTo("A Component with a role");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void viaComponentScanning() {
|
||||
void viaComponentScanning() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.role");
|
||||
ctx.refresh();
|
||||
|
@ -66,20 +66,21 @@ public class RoleAndDescriptionAnnotationTests {
|
|||
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription()).isNull();
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription()).isEqualTo("A Component with a role");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
public String foo() {
|
||||
String foo() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Description("A Bean method with a role")
|
||||
public String bar() {
|
||||
String bar() {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
|
@ -36,18 +36,20 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class Spr11202Tests {
|
||||
class Spr11202Tests {
|
||||
|
||||
@Test
|
||||
public void testWithImporter() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
|
||||
void withImporter() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
|
||||
assertThat(context.getBean("value")).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutImporter() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
void withoutImporter() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(context.getBean("value")).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -29,24 +29,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class Spr11310Tests {
|
||||
class Spr11310Tests {
|
||||
|
||||
@Test
|
||||
public void orderedList() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
void orderedList() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
StringHolder holder = context.getBean(StringHolder.class);
|
||||
assertThat(holder.itemsList.get(0)).isEqualTo("second");
|
||||
assertThat(holder.itemsList.get(1)).isEqualTo("first");
|
||||
assertThat(holder.itemsList.get(2)).isEqualTo("unknownOrder");
|
||||
assertThat(holder.itemsList).containsExactly("second", "first", "unknownOrder");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderedArray() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
void orderedArray() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
StringHolder holder = context.getBean(StringHolder.class);
|
||||
assertThat(holder.itemsArray[0]).isEqualTo("second");
|
||||
assertThat(holder.itemsArray[1]).isEqualTo("first");
|
||||
assertThat(holder.itemsArray[2]).isEqualTo("unknownOrder");
|
||||
assertThat(holder.itemsArray).containsExactly("second", "first", "unknownOrder");
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
|
@ -24,11 +24,12 @@ import org.springframework.aop.target.CommonsPool2TargetSource;
|
|||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Spr15042Tests {
|
||||
class Spr15042Tests {
|
||||
|
||||
@Test
|
||||
public void poolingTargetSource() {
|
||||
new AnnotationConfigApplicationContext(PoolingTargetSourceConfig.class);
|
||||
void poolingTargetSource() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(PoolingTargetSourceConfig.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class Spr15042Tests {
|
|||
static class PoolingTargetSourceConfig {
|
||||
|
||||
@Bean
|
||||
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Scope(scopeName = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public ProxyFactoryBean myObject() {
|
||||
ProxyFactoryBean pfb = new ProxyFactoryBean();
|
||||
pfb.setTargetSource(poolTargetSource());
|
||||
|
|
|
@ -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.
|
||||
|
@ -20,56 +20,62 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Spr15275Tests {
|
||||
class Spr15275Tests {
|
||||
|
||||
@Test
|
||||
public void testWithFactoryBean() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFactoryBean.class);
|
||||
void withFactoryBean() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFactoryBean.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithAbstractFactoryBean() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBean.class);
|
||||
void withAbstractFactoryBean() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBean.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithAbstractFactoryBeanForInterface() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanForInterface.class);
|
||||
void withAbstractFactoryBeanForInterface() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanForInterface.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithAbstractFactoryBeanAsReturnType() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanAsReturnType.class);
|
||||
void withAbstractFactoryBeanAsReturnType() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanAsReturnType.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithFinalFactoryBean() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBean.class);
|
||||
void withFinalFactoryBean() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBean.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithFinalFactoryBeanAsReturnType() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBeanAsReturnType.class);
|
||||
void withFinalFactoryBeanAsReturnType() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBeanAsReturnType.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
// not same due to fallback to raw FinalFactoryBean instance with repeated getObject() invocations
|
||||
assertThat(context.getBean(Bar.class).foo).isNotSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -26,20 +26,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class Spr16179Tests {
|
||||
class Spr16179Tests {
|
||||
|
||||
@Test
|
||||
public void repro() {
|
||||
AnnotationConfigApplicationContext bf =
|
||||
new AnnotationConfigApplicationContext(AssemblerConfig.class, AssemblerInjection.class);
|
||||
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler0).isSameAs(bf.getBean("someAssembler"));
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler1); TODO: accidental match
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler2);
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler3).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler4).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler5).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler6).isSameAs(bf.getBean("pageAssembler"));
|
||||
void repro() {
|
||||
try (AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext(AssemblerConfig.class, AssemblerInjection.class)) {
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler0).isSameAs(bf.getBean("someAssembler"));
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler1); TODO: accidental match
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler2);
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler3).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler4).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler5).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler6).isSameAs(bf.getBean("pageAssembler"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -55,46 +55,50 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class AutowiredConfigurationTests {
|
||||
class AutowiredConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testAutowiredConfigurationDependencies() {
|
||||
void testAutowiredConfigurationDependencies() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
AutowiredConfigurationTests.class.getSimpleName() + ".xml", AutowiredConfigurationTests.class);
|
||||
|
||||
assertThat(context.getBean("colour", Colour.class)).isEqualTo(Colour.RED);
|
||||
assertThat(context.getBean("testBean", TestBean.class).getName()).isEqualTo(Colour.RED.toString());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowiredConfigurationMethodDependencies() {
|
||||
void testAutowiredConfigurationMethodDependencies() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
AutowiredMethodConfig.class, ColorConfig.class);
|
||||
|
||||
assertThat(context.getBean(Colour.class)).isEqualTo(Colour.RED);
|
||||
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("RED-RED");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowiredConfigurationMethodDependenciesWithOptionalAndAvailable() {
|
||||
void testAutowiredConfigurationMethodDependenciesWithOptionalAndAvailable() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
OptionalAutowiredMethodConfig.class, ColorConfig.class);
|
||||
|
||||
assertThat(context.getBean(Colour.class)).isEqualTo(Colour.RED);
|
||||
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("RED-RED");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowiredConfigurationMethodDependenciesWithOptionalAndNotAvailable() {
|
||||
void testAutowiredConfigurationMethodDependenciesWithOptionalAndNotAvailable() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
OptionalAutowiredMethodConfig.class);
|
||||
|
||||
assertThat(context.getBeansOfType(Colour.class).isEmpty()).isTrue();
|
||||
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowiredSingleConstructorSupported() {
|
||||
void testAutowiredSingleConstructorSupported() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
new ClassPathResource("annotation-config.xml", AutowiredConstructorConfig.class));
|
||||
|
@ -103,10 +107,11 @@ public class AutowiredConfigurationTests {
|
|||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(Colour.class)).isSameAs(ctx.getBean(AutowiredConstructorConfig.class).colour);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectFactoryConstructorWithTypeVariable() {
|
||||
void testObjectFactoryConstructorWithTypeVariable() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
new ClassPathResource("annotation-config.xml", ObjectFactoryConstructorConfig.class));
|
||||
|
@ -115,10 +120,11 @@ public class AutowiredConfigurationTests {
|
|||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(Colour.class)).isSameAs(ctx.getBean(ObjectFactoryConstructorConfig.class).colour);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowiredAnnotatedConstructorSupported() {
|
||||
void testAutowiredAnnotatedConstructorSupported() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
new ClassPathResource("annotation-config.xml", MultipleConstructorConfig.class));
|
||||
|
@ -127,48 +133,55 @@ public class AutowiredConfigurationTests {
|
|||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(Colour.class)).isSameAs(ctx.getBean(MultipleConstructorConfig.class).colour);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueInjection() {
|
||||
void testValueInjection() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"ValueInjectionTests.xml", AutowiredConfigurationTests.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueInjectionWithMetaAnnotation() {
|
||||
void testValueInjectionWithMetaAnnotation() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithMetaAnnotation.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueInjectionWithAliasedMetaAnnotation() {
|
||||
void testValueInjectionWithAliasedMetaAnnotation() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithAliasedMetaAnnotation.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueInjectionWithProviderFields() {
|
||||
void testValueInjectionWithProviderFields() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithProviderFields.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueInjectionWithProviderConstructorArguments() {
|
||||
void testValueInjectionWithProviderConstructorArguments() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithProviderConstructorArguments.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueInjectionWithProviderMethodArguments() {
|
||||
void testValueInjectionWithProviderMethodArguments() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithProviderMethodArguments.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
private void doTestValueInjection(BeanFactory context) {
|
||||
|
@ -198,17 +211,18 @@ public class AutowiredConfigurationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPropertiesWithClassPathContext() throws IOException {
|
||||
void testCustomPropertiesWithClassPathContext() throws IOException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class);
|
||||
|
||||
TestBean testBean = context.getBean("testBean", TestBean.class);
|
||||
assertThat(testBean.getName()).isEqualTo("localhost");
|
||||
assertThat(testBean.getAge()).isEqualTo(contentLength());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPropertiesWithGenericContext() throws IOException {
|
||||
void testCustomPropertiesWithGenericContext() throws IOException {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
new XmlBeanDefinitionReader(context).loadBeanDefinitions(
|
||||
new ClassPathResource("AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class));
|
||||
|
@ -217,6 +231,7 @@ public class AutowiredConfigurationTests {
|
|||
TestBean testBean = context.getBean("testBean", TestBean.class);
|
||||
assertThat(testBean.getName()).isEqualTo("localhost");
|
||||
assertThat(testBean.getAge()).isEqualTo(contentLength());
|
||||
context.close();
|
||||
}
|
||||
|
||||
private int contentLength() throws IOException {
|
||||
|
|
|
@ -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.
|
||||
|
@ -44,40 +44,43 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class BeanMethodQualificationTests {
|
||||
class BeanMethodQualificationTests {
|
||||
|
||||
@Test
|
||||
public void testStandard() {
|
||||
void standard() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(StandardConfig.class, StandardPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isFalse();
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScoped() {
|
||||
void scoped() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ScopedConfig.class, StandardPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isFalse();
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScopedProxy() {
|
||||
void scopedProxy() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ScopedProxyConfig.class, StandardPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isTrue(); // a shared scoped proxy
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomWithLazyResolution() {
|
||||
void customWithLazyResolution() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(CustomConfig.class, CustomPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isFalse();
|
||||
|
@ -89,10 +92,11 @@ public class BeanMethodQualificationTests {
|
|||
TestBean testBean2 = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
|
||||
ctx.getDefaultListableBeanFactory(), TestBean.class, "boring");
|
||||
assertThat(testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomWithEarlyResolution() {
|
||||
void customWithEarlyResolution() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(CustomConfig.class, CustomPojo.class);
|
||||
ctx.refresh();
|
||||
|
@ -103,10 +107,11 @@ public class BeanMethodQualificationTests {
|
|||
"testBean2", ctx.getDefaultListableBeanFactory())).isTrue();
|
||||
CustomPojo pojo = ctx.getBean(CustomPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomWithAsm() {
|
||||
void customWithAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("customConfig", new RootBeanDefinition(CustomConfig.class.getName()));
|
||||
RootBeanDefinition customPojo = new RootBeanDefinition(CustomPojo.class.getName());
|
||||
|
@ -117,24 +122,27 @@ public class BeanMethodQualificationTests {
|
|||
assertThat(ctx.getBeanFactory().containsSingleton("testBean2")).isFalse();
|
||||
CustomPojo pojo = ctx.getBean(CustomPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomWithAttributeOverride() {
|
||||
void customWithAttributeOverride() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(CustomConfigWithAttributeOverride.class, CustomPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBeanX")).isFalse();
|
||||
CustomPojo pojo = ctx.getBean(CustomPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNamesForAnnotation() {
|
||||
void beanNamesForAnnotation() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(StandardConfig.class);
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Configuration.class)).isEqualTo(new String[] {"beanMethodQualificationTests.StandardConfig"});
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Scope.class)).isEqualTo(new String[] {});
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Lazy.class)).isEqualTo(new String[] {"testBean1"});
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Boring.class)).isEqualTo(new String[] {"testBean2"});
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,31 +249,31 @@ public class BeanMethodQualificationTests {
|
|||
|
||||
@Bean @Lazy @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InterestingBean {
|
||||
@interface InterestingBean {
|
||||
}
|
||||
|
||||
@Bean @Lazy @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InterestingBeanWithName {
|
||||
@interface InterestingBeanWithName {
|
||||
|
||||
String name();
|
||||
}
|
||||
|
||||
@Autowired @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InterestingNeed {
|
||||
@interface InterestingNeed {
|
||||
}
|
||||
|
||||
@Autowired @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InterestingNeedWithRequiredOverride {
|
||||
@interface InterestingNeedWithRequiredOverride {
|
||||
|
||||
boolean required();
|
||||
}
|
||||
|
||||
@Component @Lazy
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InterestingPojo {
|
||||
@interface InterestingPojo {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -29,7 +29,6 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests ensuring that configuration class bean names as expressed via @Configuration
|
||||
* or @Component 'value' attributes are indeed respected, and that customization of bean
|
||||
|
@ -38,32 +37,30 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public class ConfigurationBeanNameTests {
|
||||
class ConfigurationBeanNameTests {
|
||||
|
||||
@Test
|
||||
public void registerOuterConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(A.class);
|
||||
ctx.refresh();
|
||||
void registerOuterConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(A.class);
|
||||
assertThat(ctx.containsBean("outer")).isTrue();
|
||||
assertThat(ctx.containsBean("imported")).isTrue();
|
||||
assertThat(ctx.containsBean("nested")).isTrue();
|
||||
assertThat(ctx.containsBean("nestedBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerNestedConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(A.B.class);
|
||||
ctx.refresh();
|
||||
void registerNestedConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(A.B.class);
|
||||
assertThat(ctx.containsBean("outer")).isFalse();
|
||||
assertThat(ctx.containsBean("imported")).isFalse();
|
||||
assertThat(ctx.containsBean("nested")).isTrue();
|
||||
assertThat(ctx.containsBean("nestedBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerOuterConfig_withBeanNameGenerator() {
|
||||
void registerOuterConfig_withBeanNameGenerator() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
|
||||
@Override
|
||||
|
@ -78,6 +75,7 @@ public class ConfigurationBeanNameTests {
|
|||
assertThat(ctx.containsBean("custom-imported")).isTrue();
|
||||
assertThat(ctx.containsBean("custom-nested")).isTrue();
|
||||
assertThat(ctx.containsBean("nestedBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Configuration("outer")
|
||||
|
@ -93,4 +91,5 @@ public class ConfigurationBeanNameTests {
|
|||
static class C {
|
||||
@Bean public String s() { return "s"; }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -26,7 +26,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -37,7 +37,6 @@ import org.springframework.core.io.ClassPathResource;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* System tests covering use of AspectJ {@link Aspect}s in conjunction with {@link Configuration} classes.
|
||||
* {@link Bean} methods may return aspects, or Configuration classes may themselves be annotated with Aspect.
|
||||
|
@ -51,15 +50,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ConfigurationClassAspectIntegrationTests {
|
||||
class ConfigurationClassAspectIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void aspectAnnotatedConfiguration() {
|
||||
void aspectAnnotatedConfiguration() {
|
||||
assertAdviceWasApplied(AspectConfig.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationIncludesAspect() {
|
||||
void configurationIncludesAspect() {
|
||||
assertAdviceWasApplied(ConfigurationWithAspect.class);
|
||||
}
|
||||
|
||||
|
@ -76,15 +75,17 @@ public class ConfigurationClassAspectIntegrationTests {
|
|||
assertThat(testBean.getName()).isEqualTo("name");
|
||||
testBean.absquatulate();
|
||||
assertThat(testBean.getName()).isEqualTo("advisedName");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInnerClassAndLambdaExpression() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Application.class, CountingAspect.class);
|
||||
void withInnerClassAndLambdaExpression() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Application.class, CountingAspect.class);
|
||||
ctx.getBeansOfType(Runnable.class).forEach((k, v) -> v.run());
|
||||
|
||||
// TODO: returns just 1 as of AspectJ 1.9 beta 3, not detecting the applicable lambda expression anymore
|
||||
// assertEquals(2, ctx.getBean(CountingAspect.class).count);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,16 +69,16 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ConfigurationClassProcessingTests {
|
||||
class ConfigurationClassProcessingTests {
|
||||
|
||||
@Test
|
||||
public void customBeanNameIsRespectedWhenConfiguredViaNameAttribute() {
|
||||
void customBeanNameIsRespectedWhenConfiguredViaNameAttribute() {
|
||||
customBeanNameIsRespected(ConfigWithBeanWithCustomName.class,
|
||||
() -> ConfigWithBeanWithCustomName.testBean, "customName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customBeanNameIsRespectedWhenConfiguredViaValueAttribute() {
|
||||
void customBeanNameIsRespectedWhenConfiguredViaValueAttribute() {
|
||||
customBeanNameIsRespected(ConfigWithBeanWithCustomNameConfiguredViaValueAttribute.class,
|
||||
() -> ConfigWithBeanWithCustomNameConfiguredViaValueAttribute.testBean, "enigma");
|
||||
}
|
||||
|
@ -97,13 +97,13 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void aliasesAreRespectedWhenConfiguredViaNameAttribute() {
|
||||
void aliasesAreRespectedWhenConfiguredViaNameAttribute() {
|
||||
aliasesAreRespected(ConfigWithBeanWithAliases.class,
|
||||
() -> ConfigWithBeanWithAliases.testBean, "name1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aliasesAreRespectedWhenConfiguredViaValueAttribute() {
|
||||
void aliasesAreRespectedWhenConfiguredViaValueAttribute() {
|
||||
aliasesAreRespected(ConfigWithBeanWithAliasesConfiguredViaValueAttribute.class,
|
||||
() -> ConfigWithBeanWithAliasesConfiguredViaValueAttribute.testBean, "enigma");
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test // SPR-11830
|
||||
public void configWithBeanWithProviderImplementation() {
|
||||
void configWithBeanWithProviderImplementation() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
|
||||
ac.registerBeanDefinition("config", new RootBeanDefinition(ConfigWithBeanWithProviderImplementation.class));
|
||||
|
@ -130,7 +130,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test // SPR-11830
|
||||
public void configWithSetWithProviderImplementation() {
|
||||
void configWithSetWithProviderImplementation() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
|
||||
ac.registerBeanDefinition("config", new RootBeanDefinition(ConfigWithSetWithProviderImplementation.class));
|
||||
|
@ -139,20 +139,20 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFinalBeanMethod() {
|
||||
void finalBeanMethod() {
|
||||
assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() ->
|
||||
initBeanFactory(ConfigWithFinalBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simplestPossibleConfig() {
|
||||
void simplestPossibleConfig() {
|
||||
BeanFactory factory = initBeanFactory(SimplestPossibleConfig.class);
|
||||
String stringBean = factory.getBean("stringBean", String.class);
|
||||
assertThat(stringBean).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configWithObjectReturnType() {
|
||||
void configWithObjectReturnType() {
|
||||
BeanFactory factory = initBeanFactory(ConfigWithNonSpecificReturnTypes.class);
|
||||
assertThat(factory.getType("stringBean")).isEqualTo(Object.class);
|
||||
assertThat(factory.isTypeMatch("stringBean", String.class)).isFalse();
|
||||
|
@ -161,7 +161,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configWithFactoryBeanReturnType() {
|
||||
void configWithFactoryBeanReturnType() {
|
||||
ListableBeanFactory factory = initBeanFactory(ConfigWithNonSpecificReturnTypes.class);
|
||||
assertThat(factory.getType("factoryBean")).isEqualTo(List.class);
|
||||
assertThat(factory.isTypeMatch("factoryBean", List.class)).isTrue();
|
||||
|
@ -189,7 +189,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithPrototypeScopedBeans() {
|
||||
void configurationWithPrototypeScopedBeans() {
|
||||
BeanFactory factory = initBeanFactory(ConfigWithPrototypeBean.class);
|
||||
|
||||
TestBean foo = factory.getBean("foo", TestBean.class);
|
||||
|
@ -201,7 +201,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithNullReference() {
|
||||
void configurationWithNullReference() {
|
||||
BeanFactory factory = initBeanFactory(ConfigWithNullReference.class);
|
||||
|
||||
TestBean foo = factory.getBean("foo", TestBean.class);
|
||||
|
@ -210,7 +210,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithAdaptivePrototypes() {
|
||||
void configurationWithAdaptivePrototypes() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithPrototypeBean.class, AdaptiveInjectionPoints.class);
|
||||
ctx.refresh();
|
||||
|
@ -226,7 +226,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithAdaptiveResourcePrototypes() {
|
||||
void configurationWithAdaptiveResourcePrototypes() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithPrototypeBean.class, AdaptiveResourceInjectionPoints.class);
|
||||
ctx.refresh();
|
||||
|
@ -242,7 +242,7 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithPostProcessor() {
|
||||
void configurationWithPostProcessor() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithPostProcessor.class);
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -266,17 +266,18 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithFunctionalRegistration() {
|
||||
void configurationWithFunctionalRegistration() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithFunctionalRegistration.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getBean(TestBean.class).getSpouse()).isSameAs(ctx.getBean("spouse"));
|
||||
assertThat(ctx.getBean(NestedTestBean.class).getCompany()).isEqualTo("functional");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithApplicationListener() {
|
||||
void configurationWithApplicationListener() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithApplicationListener.class);
|
||||
ctx.refresh();
|
||||
|
@ -288,27 +289,29 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithOverloadedBeanMismatch() {
|
||||
void configurationWithOverloadedBeanMismatch() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config", new RootBeanDefinition(OverloadedBeanMismatch.class));
|
||||
ctx.refresh();
|
||||
|
||||
TestBean tb = ctx.getBean(TestBean.class);
|
||||
assertThat(tb.getLawyer()).isEqualTo(ctx.getBean(NestedTestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationWithOverloadedBeanMismatchWithAsm() {
|
||||
void configurationWithOverloadedBeanMismatchWithAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config", new RootBeanDefinition(OverloadedBeanMismatch.class.getName()));
|
||||
ctx.refresh();
|
||||
|
||||
TestBean tb = ctx.getBean(TestBean.class);
|
||||
assertThat(tb.getLawyer()).isEqualTo(ctx.getBean(NestedTestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test // gh-26019
|
||||
public void autowiringWithDynamicPrototypeBeanClass() {
|
||||
void autowiringWithDynamicPrototypeBeanClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||
ConfigWithDynamicPrototype.class, PrototypeDependency.class);
|
||||
|
||||
|
@ -322,6 +325,7 @@ public class ConfigurationClassProcessingTests {
|
|||
PrototypeInterface p3 = ctx.getBean(PrototypeInterface.class, 1);
|
||||
assertThat(p3).isInstanceOf(PrototypeOne.class);
|
||||
assertThat(((PrototypeOne) p3).prototypeDependency).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -658,7 +662,6 @@ public class ConfigurationClassProcessingTests {
|
|||
}
|
||||
|
||||
static class PrototypeTwo extends AbstractPrototype {
|
||||
|
||||
// no autowired dependency here, in contrast to above
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -28,37 +28,35 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Ensures that @Configuration is supported properly as a meta-annotation.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ConfigurationMetaAnnotationTests {
|
||||
class ConfigurationMetaAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void customConfigurationStereotype() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config.class);
|
||||
ctx.refresh();
|
||||
void customConfigurationStereotype() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(ctx.containsBean("customName")).isTrue();
|
||||
TestBean a = ctx.getBean("a", TestBean.class);
|
||||
TestBean b = ctx.getBean("b", TestBean.class);
|
||||
assertThat(b).isSameAs(a.getSpouse());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@TestConfiguration("customName")
|
||||
static class Config {
|
||||
@Bean
|
||||
public TestBean a() {
|
||||
TestBean a() {
|
||||
TestBean a = new TestBean();
|
||||
a.setSpouse(b());
|
||||
return a;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestBean b() {
|
||||
TestBean b() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +64,7 @@ public class ConfigurationMetaAnnotationTests {
|
|||
|
||||
@Configuration
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TestConfiguration {
|
||||
@interface TestConfiguration {
|
||||
String value() default "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
|
@ -33,22 +33,24 @@ import org.springframework.context.support.GenericApplicationContext;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class DuplicateConfigurationClassPostProcessorTests {
|
||||
class DuplicateConfigurationClassPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void repro() {
|
||||
void repro() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.registerBeanDefinition("a", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
|
||||
ctx.registerBeanDefinition("b", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
|
||||
ctx.registerBeanDefinition("myConfig", new RootBeanDefinition(Config.class));
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
public String string() {
|
||||
String string() {
|
||||
return "bean";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
|
@ -33,15 +33,15 @@ import org.springframework.context.annotation.Bean;
|
|||
* @author Andy Wilkinson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class DuplicatePostProcessingTests {
|
||||
class DuplicatePostProcessingTests {
|
||||
|
||||
@Test
|
||||
public void testWithFactoryBeanAndEventListener() {
|
||||
@SuppressWarnings("resource")
|
||||
void withFactoryBeanAndEventListener() {
|
||||
new AnnotationConfigApplicationContext(Config.class).getBean(ExampleBean.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -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.
|
||||
|
@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ImportTests {
|
||||
class ImportTests {
|
||||
|
||||
private DefaultListableBeanFactory processConfigurationClasses(Class<?>... classes) {
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
@ -60,7 +60,7 @@ public class ImportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProcessImportsWithAsm() {
|
||||
void testProcessImportsWithAsm() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
@ -71,21 +71,21 @@ public class ImportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProcessImportsWithDoubleImports() {
|
||||
void testProcessImportsWithDoubleImports() {
|
||||
int configClasses = 3;
|
||||
int beansInClasses = 3;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), ConfigurationWithImportAnnotation.class, OtherConfigurationWithImportAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessImportsWithExplicitOverridingBefore() {
|
||||
void testProcessImportsWithExplicitOverridingBefore() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), OtherConfiguration.class, ConfigurationWithImportAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessImportsWithExplicitOverridingAfter() {
|
||||
void testProcessImportsWithExplicitOverridingAfter() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), ConfigurationWithImportAnnotation.class, OtherConfiguration.class);
|
||||
|
@ -95,7 +95,7 @@ public class ImportTests {
|
|||
@Import(OtherConfiguration.class)
|
||||
static class ConfigurationWithImportAnnotation {
|
||||
@Bean
|
||||
public ITestBean one() {
|
||||
ITestBean one() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class ImportTests {
|
|||
@Import(OtherConfiguration.class)
|
||||
static class OtherConfigurationWithImportAnnotation {
|
||||
@Bean
|
||||
public ITestBean two() {
|
||||
ITestBean two() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class OtherConfiguration {
|
||||
@Bean
|
||||
public ITestBean three() {
|
||||
ITestBean three() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class ImportTests {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testImportAnnotationWithTwoLevelRecursion() {
|
||||
void testImportAnnotationWithTwoLevelRecursion() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 3;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), AppConfig.class);
|
||||
|
@ -131,12 +131,12 @@ public class ImportTests {
|
|||
static class AppConfig {
|
||||
|
||||
@Bean
|
||||
public ITestBean transferService() {
|
||||
ITestBean transferService() {
|
||||
return new TestBean(accountRepository());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ITestBean accountRepository() {
|
||||
ITestBean accountRepository() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class DataSourceConfig {
|
||||
@Bean
|
||||
public ITestBean dataSourceA() {
|
||||
ITestBean dataSourceA() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public class ImportTests {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testImportAnnotationWithThreeLevelRecursion() {
|
||||
void testImportAnnotationWithThreeLevelRecursion() {
|
||||
int configClasses = 4;
|
||||
int beansInClasses = 5;
|
||||
assertBeanDefinitionCount(configClasses + beansInClasses, FirstLevel.class);
|
||||
|
@ -161,7 +161,7 @@ public class ImportTests {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testImportAnnotationWithMultipleArguments() {
|
||||
void testImportAnnotationWithMultipleArguments() {
|
||||
int configClasses = 3;
|
||||
int beansInClasses = 3;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), WithMultipleArgumentsToImportAnnotation.class);
|
||||
|
@ -169,7 +169,7 @@ public class ImportTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() {
|
||||
void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() {
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(
|
||||
WithMultipleArgumentsThatWillCauseDuplication.class));
|
||||
|
@ -187,7 +187,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class Foo1 {
|
||||
@Bean
|
||||
public ITestBean foo() {
|
||||
ITestBean foo() {
|
||||
return new TestBean("foo1");
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class Foo2 {
|
||||
@Bean
|
||||
public ITestBean foo() {
|
||||
ITestBean foo() {
|
||||
return new TestBean("foo2");
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public class ImportTests {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testImportAnnotationOnInnerClasses() {
|
||||
void testImportAnnotationOnInnerClasses() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), OuterConfig.InnerConfig.class);
|
||||
|
@ -220,7 +220,7 @@ public class ImportTests {
|
|||
@Import(ExternalConfig.class)
|
||||
static class InnerConfig {
|
||||
@Bean
|
||||
public ITestBean innerBean() {
|
||||
ITestBean innerBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class ExternalConfig {
|
||||
@Bean
|
||||
public ITestBean extBean() {
|
||||
ITestBean extBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ public class ImportTests {
|
|||
@Import(SecondLevel.class)
|
||||
static class FirstLevel {
|
||||
@Bean
|
||||
public TestBean m() {
|
||||
TestBean m() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ public class ImportTests {
|
|||
@Import({ThirdLevel.class, InitBean.class})
|
||||
static class SecondLevel {
|
||||
@Bean
|
||||
public TestBean n() {
|
||||
TestBean n() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -257,22 +257,22 @@ public class ImportTests {
|
|||
@Configuration
|
||||
@DependsOn("org.springframework.context.annotation.configuration.ImportTests$InitBean")
|
||||
static class ThirdLevel {
|
||||
public ThirdLevel() {
|
||||
ThirdLevel() {
|
||||
assertThat(InitBean.initialized).isTrue();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ITestBean thirdLevelA() {
|
||||
ITestBean thirdLevelA() {
|
||||
return new TestBean();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ITestBean thirdLevelB() {
|
||||
ITestBean thirdLevelB() {
|
||||
return new TestBean();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ITestBean thirdLevelC() {
|
||||
ITestBean thirdLevelC() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ public class ImportTests {
|
|||
static class InitBean {
|
||||
public static boolean initialized = false;
|
||||
|
||||
public InitBean() {
|
||||
InitBean() {
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ public class ImportTests {
|
|||
@Import({LeftConfig.class, RightConfig.class})
|
||||
static class WithMultipleArgumentsToImportAnnotation {
|
||||
@Bean
|
||||
public TestBean m() {
|
||||
TestBean m() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class LeftConfig {
|
||||
@Bean
|
||||
public ITestBean left() {
|
||||
ITestBean left() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ public class ImportTests {
|
|||
@Configuration
|
||||
static class RightConfig {
|
||||
@Bean
|
||||
public ITestBean right() {
|
||||
ITestBean right() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ public class ImportTests {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testImportNonConfigurationAnnotationClass() {
|
||||
void testImportNonConfigurationAnnotationClass() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 0;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), ConfigAnnotated.class);
|
||||
|
@ -333,13 +333,13 @@ public class ImportTests {
|
|||
* or in the case of automatic registration via nesting
|
||||
*/
|
||||
@Test
|
||||
public void reproSpr9023() {
|
||||
void reproSpr9023() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(B.class);
|
||||
ctx.refresh();
|
||||
System.out.println(ctx.getBeanFactory());
|
||||
assertThat(ctx.getBeanNamesForType(B.class)[0]).isEqualTo("config-b");
|
||||
assertThat(ctx.getBeanNamesForType(A.class)[0]).isEqualTo("config-a");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Configuration("config-a")
|
||||
|
@ -350,7 +350,7 @@ public class ImportTests {
|
|||
static class B { }
|
||||
|
||||
@Test
|
||||
public void testProcessImports() {
|
||||
void testProcessImports() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), ConfigurationWithImportAnnotation.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -35,52 +35,55 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ImportedConfigurationClassEnhancementTests {
|
||||
class ImportedConfigurationClassEnhancementTests {
|
||||
|
||||
@Test
|
||||
public void autowiredConfigClassIsEnhancedWhenImported() {
|
||||
void autowiredConfigClassIsEnhancedWhenImported() {
|
||||
autowiredConfigClassIsEnhanced(ConfigThatDoesImport.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autowiredConfigClassIsEnhancedWhenRegisteredViaConstructor() {
|
||||
void autowiredConfigClassIsEnhancedWhenRegisteredViaConstructor() {
|
||||
autowiredConfigClassIsEnhanced(ConfigThatDoesNotImport.class, ConfigToBeAutowired.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void autowiredConfigClassIsEnhanced(Class<?>... configClasses) {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses);
|
||||
Config config = ctx.getBean(Config.class);
|
||||
assertThat(ClassUtils.isCglibProxy(config.autowiredConfig)).as("autowired config class has not been enhanced").isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void autowiredConfigClassBeanMethodsRespectScopingWhenImported() {
|
||||
void autowiredConfigClassBeanMethodsRespectScopingWhenImported() {
|
||||
autowiredConfigClassBeanMethodsRespectScoping(ConfigThatDoesImport.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autowiredConfigClassBeanMethodsRespectScopingWhenRegisteredViaConstructor() {
|
||||
void autowiredConfigClassBeanMethodsRespectScopingWhenRegisteredViaConstructor() {
|
||||
autowiredConfigClassBeanMethodsRespectScoping(ConfigThatDoesNotImport.class, ConfigToBeAutowired.class);
|
||||
}
|
||||
|
||||
private void autowiredConfigClassBeanMethodsRespectScoping(Class<?>... configClasses) {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses);
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses);
|
||||
Config config = ctx.getBean(Config.class);
|
||||
TestBean testBean1 = config.autowiredConfig.testBean();
|
||||
TestBean testBean2 = config.autowiredConfig.testBean();
|
||||
assertThat(testBean1)
|
||||
.as("got two distinct instances of testBean when singleton scoping was expected")
|
||||
.isSameAs(testBean2);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void importingNonConfigurationClassCausesBeanDefinitionParsingException() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigThatImportsNonConfigClass.class);
|
||||
void importingNonConfigurationClassCausesBeanDefinitionParsingException() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigThatImportsNonConfigClass.class);
|
||||
ConfigThatImportsNonConfigClass config = ctx.getBean(ConfigThatImportsNonConfigClass.class);
|
||||
assertThat(config.testBean).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,7 +91,7 @@ public class ImportedConfigurationClassEnhancementTests {
|
|||
@Configuration
|
||||
static class ConfigToBeAutowired {
|
||||
|
||||
public @Bean TestBean testBean() {
|
||||
@Bean TestBean testBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -24,7 +24,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Reproduces SPR-8756, which has been marked as "won't fix" for reasons
|
||||
* described in the issue. Also demonstrates the suggested workaround.
|
||||
|
@ -34,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class PackagePrivateBeanMethodInheritanceTests {
|
||||
|
||||
@Test
|
||||
public void repro() {
|
||||
void repro() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ReproConfig.class);
|
||||
ctx.refresh();
|
||||
|
@ -42,10 +41,11 @@ public class PackagePrivateBeanMethodInheritanceTests {
|
|||
Foo foo2 = ctx.getBean("foo2", Foo.class);
|
||||
ctx.getBean("packagePrivateBar", Bar.class); // <-- i.e. @Bean was registered
|
||||
assertThat(foo1.bar).isNotEqualTo(foo2.bar); // <-- i.e. @Bean *not* enhanced
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workaround() {
|
||||
void workaround() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(WorkaroundConfig.class);
|
||||
ctx.refresh();
|
||||
|
@ -53,8 +53,10 @@ public class PackagePrivateBeanMethodInheritanceTests {
|
|||
Foo foo2 = ctx.getBean("foo2", Foo.class);
|
||||
ctx.getBean("protectedBar", Bar.class); // <-- i.e. @Bean was registered
|
||||
assertThat(foo1.bar).isEqualTo(foo2.bar); // <-- i.e. @Bean *was* enhanced
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
public static class Foo {
|
||||
final Bar bar;
|
||||
public Foo(Bar bar) {
|
||||
|
@ -90,5 +92,5 @@ public class PackagePrivateBeanMethodInheritanceTests {
|
|||
return new Foo(workaroundBar());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -30,11 +30,11 @@ import org.springframework.util.ClassUtils;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class Spr7167Tests {
|
||||
class Spr7167Tests {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void test() {
|
||||
@SuppressWarnings({ "deprecation", "resource" })
|
||||
void test() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
|
||||
|
||||
assertThat(ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -24,13 +24,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|||
* @author Chris Beams
|
||||
* @author Willem Dekker
|
||||
*/
|
||||
public class Spr8955Tests {
|
||||
class Spr8955Tests {
|
||||
|
||||
@Test
|
||||
public void repro() {
|
||||
void repro() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.configuration.spr8955");
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -31,7 +31,6 @@ import org.springframework.context.annotation.configuration.spr9031.scanpackage.
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests cornering bug SPR-9031.
|
||||
*
|
||||
|
@ -45,11 +44,10 @@ public class Spr9031Tests {
|
|||
* processing.
|
||||
*/
|
||||
@Test
|
||||
public void withAsmAnnotationProcessing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(HighLevelConfig.class);
|
||||
ctx.refresh();
|
||||
void withAsmAnnotationProcessing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(HighLevelConfig.class);
|
||||
assertThat(ctx.getBean(LowLevelConfig.class).scanned).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,13 +55,13 @@ public class Spr9031Tests {
|
|||
* processing.
|
||||
*/
|
||||
@Test
|
||||
public void withoutAsmAnnotationProcessing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(LowLevelConfig.class);
|
||||
ctx.refresh();
|
||||
void withoutAsmAnnotationProcessing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(LowLevelConfig.class);
|
||||
assertThat(ctx.getBean(LowLevelConfig.class).scanned).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(LowLevelConfig.class)
|
||||
static class HighLevelConfig {}
|
||||
|
@ -80,4 +78,5 @@ public class Spr9031Tests {
|
|||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MarkerAnnotation {}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
|
@ -16,6 +16,10 @@
|
|||
|
||||
package org.springframework.context.annotation.spr12334;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
|
@ -25,44 +29,51 @@ import org.springframework.context.annotation.Import;
|
|||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Alex Pogrebnyak
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class Spr12334Tests {
|
||||
class Spr12334Tests {
|
||||
|
||||
@Test
|
||||
public void shouldNotScanTwice() {
|
||||
TestImport.scanned = false;
|
||||
void shouldNotScanTwice() {
|
||||
TestImport.scanned.set(0);
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.scan(TestImport.class.getPackage().getName());
|
||||
context.refresh();
|
||||
context.getBean(TestConfiguration.class);
|
||||
assertThat(TestImport.scanned).hasValue(1);
|
||||
assertThatNoException().isThrownBy(() -> context.getBean(TestConfiguration.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Import(TestImport.class)
|
||||
public @interface AnotherImport {
|
||||
@interface AnotherImport {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@AnotherImport
|
||||
public static class TestConfiguration {
|
||||
static class TestConfiguration {
|
||||
}
|
||||
|
||||
|
||||
public static class TestImport implements ImportBeanDefinitionRegistrar {
|
||||
static class TestImport implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
private static boolean scanned = false;
|
||||
private static AtomicInteger scanned = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
|
||||
if (scanned) {
|
||||
if (scanned.get() > 0) {
|
||||
throw new IllegalStateException("Already scanned");
|
||||
}
|
||||
scanned = true;
|
||||
scanned.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
|
@ -23,15 +23,16 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Spr16756Tests {
|
||||
class Spr16756Tests {
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnNestedScopedComponent() {
|
||||
void shouldNotFailOnNestedScopedComponent() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(ScanningConfiguration.class);
|
||||
context.refresh();
|
||||
context.getBean(ScannedComponent.class);
|
||||
context.getBean(ScannedComponent.State.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -26,24 +26,24 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests cornering the regression reported in SPR-8761.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class Spr8761Tests {
|
||||
class Spr8761Tests {
|
||||
|
||||
/**
|
||||
* Prior to the fix for SPR-8761, this test threw because the nested MyComponent
|
||||
* annotation was being falsely considered as a 'lite' Configuration class candidate.
|
||||
*/
|
||||
@Test
|
||||
public void repro() {
|
||||
void repro() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan(getClass().getPackage().getName());
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean("withNestedAnnotation")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
|
@ -29,17 +29,16 @@ import org.springframework.context.annotation.Configuration;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class Spr8808Tests {
|
||||
class Spr8808Tests {
|
||||
|
||||
/**
|
||||
* This test failed with ConflictingBeanDefinitionException prior to fixes for
|
||||
* SPR-8808.
|
||||
*/
|
||||
@Test
|
||||
public void repro() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config.class);
|
||||
ctx.refresh();
|
||||
void repro() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -23,7 +23,7 @@ import org.junit.jupiter.api.AfterEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
@ -39,30 +39,32 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @author Juergen Hoeller
|
||||
* @since 2.5.6
|
||||
*/
|
||||
public class ContextNamespaceHandlerTests {
|
||||
class ContextNamespaceHandlerTests {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
System.getProperties().remove("foo");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholder() {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
void propertyPlaceholder() {
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-replace.xml", getClass());
|
||||
assertThat(applicationContext.getBean("string")).isEqualTo("bar");
|
||||
assertThat(applicationContext.getBean("nullString")).isEqualTo("null");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderSystemProperties() {
|
||||
void propertyPlaceholderSystemProperties() {
|
||||
String value = System.setProperty("foo", "spam");
|
||||
try {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-system.xml", getClass());
|
||||
assertThat(applicationContext.getBean("string")).isEqualTo("spam");
|
||||
assertThat(applicationContext.getBean("fallback")).isEqualTo("none");
|
||||
applicationContext.close();
|
||||
}
|
||||
finally {
|
||||
if (value != null) {
|
||||
|
@ -72,7 +74,7 @@ public class ContextNamespaceHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderEnvironmentProperties() {
|
||||
void propertyPlaceholderEnvironmentProperties() {
|
||||
MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
|
||||
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
|
||||
applicationContext.setEnvironment(env);
|
||||
|
@ -80,27 +82,30 @@ public class ContextNamespaceHandlerTests {
|
|||
applicationContext.refresh();
|
||||
assertThat(applicationContext.getBean("string")).isEqualTo("spam");
|
||||
assertThat(applicationContext.getBean("fallback")).isEqualTo("none");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderLocation() {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
void propertyPlaceholderLocation() {
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-location.xml", getClass());
|
||||
assertThat(applicationContext.getBean("foo")).isEqualTo("bar");
|
||||
assertThat(applicationContext.getBean("bar")).isEqualTo("foo");
|
||||
assertThat(applicationContext.getBean("spam")).isEqualTo("maps");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderLocationWithSystemPropertyForOneLocation() {
|
||||
void propertyPlaceholderLocationWithSystemPropertyForOneLocation() {
|
||||
System.setProperty("properties",
|
||||
"classpath*:/org/springframework/context/config/test-*.properties");
|
||||
try {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-location-placeholder.xml", getClass());
|
||||
assertThat(applicationContext.getBean("foo")).isEqualTo("bar");
|
||||
assertThat(applicationContext.getBean("bar")).isEqualTo("foo");
|
||||
assertThat(applicationContext.getBean("spam")).isEqualTo("maps");
|
||||
applicationContext.close();
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("properties");
|
||||
|
@ -108,17 +113,18 @@ public class ContextNamespaceHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderLocationWithSystemPropertyForMultipleLocations() {
|
||||
void propertyPlaceholderLocationWithSystemPropertyForMultipleLocations() {
|
||||
System.setProperty("properties",
|
||||
"classpath*:/org/springframework/context/config/test-*.properties," +
|
||||
"classpath*:/org/springframework/context/config/empty-*.properties," +
|
||||
"classpath*:/org/springframework/context/config/missing-*.properties");
|
||||
try {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-location-placeholder.xml", getClass());
|
||||
assertThat(applicationContext.getBean("foo")).isEqualTo("bar");
|
||||
assertThat(applicationContext.getBean("bar")).isEqualTo("foo");
|
||||
assertThat(applicationContext.getBean("spam")).isEqualTo("maps");
|
||||
applicationContext.close();
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("properties");
|
||||
|
@ -126,7 +132,7 @@ public class ContextNamespaceHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderLocationWithSystemPropertyMissing() {
|
||||
void propertyPlaceholderLocationWithSystemPropertyMissing() {
|
||||
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-location-placeholder.xml", getClass()))
|
||||
.havingRootCause()
|
||||
|
@ -135,21 +141,23 @@ public class ContextNamespaceHandlerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderIgnored() {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
void propertyPlaceholderIgnored() {
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-replace-ignore.xml", getClass());
|
||||
assertThat(applicationContext.getBean("string")).isEqualTo("${bar}");
|
||||
assertThat(applicationContext.getBean("nullString")).isEqualTo("null");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyOverride() {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
void propertyOverride() {
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-override.xml", getClass());
|
||||
Date date = (Date) applicationContext.getBean("date");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
assertThat(calendar.get(Calendar.MINUTE)).isEqualTo(42);
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -25,16 +25,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class ConversionServiceContextConfigTests {
|
||||
class ConversionServiceContextConfigTests {
|
||||
|
||||
@Test
|
||||
public void testConfigOk() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/conversionservice/conversionService.xml");
|
||||
TestClient client = context.getBean("testClient", TestClient.class);
|
||||
assertThat(client.getBars().size()).isEqualTo(2);
|
||||
assertThat(client.getBars().get(0).getValue()).isEqualTo("value1");
|
||||
assertThat(client.getBars().get(1).getValue()).isEqualTo("value2");
|
||||
assertThat(client.isBool()).isTrue();
|
||||
void testConfigOk() {
|
||||
try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/conversionservice/conversionService.xml")) {
|
||||
TestClient client = context.getBean("testClient", TestClient.class);
|
||||
assertThat(client.getBars().size()).isEqualTo(2);
|
||||
assertThat(client.getBars().get(0).getValue()).isEqualTo("value1");
|
||||
assertThat(client.getBars().get(1).getValue()).isEqualTo("value2");
|
||||
assertThat(client.isBool()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.context.event;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
|
@ -39,23 +40,25 @@ import static org.mockito.Mockito.mock;
|
|||
* @author Juergen Hoeller
|
||||
* @author Rick Evans
|
||||
*/
|
||||
public class EventPublicationInterceptorTests {
|
||||
class EventPublicationInterceptorTests {
|
||||
|
||||
private final ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
|
||||
private final EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
|
||||
this.interceptor.setApplicationEventPublisher(publisher);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithNoApplicationEventClassSupplied() {
|
||||
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
||||
interceptor.setApplicationEventPublisher(this.publisher);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
interceptor::afterPropertiesSet);
|
||||
void withNoApplicationEventClassSupplied() {
|
||||
assertThatIllegalArgumentException().isThrownBy(interceptor::afterPropertiesSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNonApplicationEventClassSupplied() {
|
||||
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
||||
interceptor.setApplicationEventPublisher(this.publisher);
|
||||
void withNonApplicationEventClassSupplied() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> {
|
||||
interceptor.setApplicationEventClass(getClass());
|
||||
interceptor.afterPropertiesSet();
|
||||
|
@ -63,9 +66,7 @@ public class EventPublicationInterceptorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithAbstractStraightApplicationEventClassSupplied() {
|
||||
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
||||
interceptor.setApplicationEventPublisher(this.publisher);
|
||||
void withAbstractStraightApplicationEventClassSupplied() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> {
|
||||
interceptor.setApplicationEventClass(ApplicationEvent.class);
|
||||
interceptor.afterPropertiesSet();
|
||||
|
@ -73,9 +74,7 @@ public class EventPublicationInterceptorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithApplicationEventClassThatDoesntExposeAValidCtor() {
|
||||
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
||||
interceptor.setApplicationEventPublisher(this.publisher);
|
||||
void withApplicationEventClassThatDoesntExposeAValidCtor() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> {
|
||||
interceptor.setApplicationEventClass(TestEventWithNoValidOneArgObjectCtor.class);
|
||||
interceptor.afterPropertiesSet();
|
||||
|
@ -83,7 +82,7 @@ public class EventPublicationInterceptorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testExpectedBehavior() {
|
||||
void expectedBehavior() {
|
||||
TestBean target = new TestBean();
|
||||
final TestApplicationListener listener = new TestApplicationListener();
|
||||
|
||||
|
@ -116,11 +115,12 @@ public class EventPublicationInterceptorTests {
|
|||
assertThat(listener.getEventCount() == 2).as("Interceptor must have published 2 events").isTrue();
|
||||
TestApplicationListener otherListener = (TestApplicationListener) ctx.getBean("&otherListener");
|
||||
assertThat(otherListener.getEventCount() == 2).as("Interceptor must have published 2 events").isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static final class TestEventWithNoValidOneArgObjectCtor extends ApplicationEvent {
|
||||
static final class TestEventWithNoValidOneArgObjectCtor extends ApplicationEvent {
|
||||
|
||||
public TestEventWithNoValidOneArgObjectCtor() {
|
||||
super("");
|
||||
|
@ -128,7 +128,7 @@ public class EventPublicationInterceptorTests {
|
|||
}
|
||||
|
||||
|
||||
public static class FactoryBeanTestListener extends TestApplicationListener implements FactoryBean<Object> {
|
||||
static class FactoryBeanTestListener extends TestApplicationListener implements FactoryBean<Object> {
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -21,7 +21,6 @@ import java.util.List;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.PayloadApplicationEvent;
|
||||
|
@ -38,11 +37,12 @@ public class PayloadApplicationEventTests {
|
|||
|
||||
@Test
|
||||
public void testEventClassWithInterface() {
|
||||
ApplicationContext ac = new AnnotationConfigApplicationContext(AuditableListener.class);
|
||||
ConfigurableApplicationContext ac = new AnnotationConfigApplicationContext(AuditableListener.class);
|
||||
|
||||
AuditablePayloadEvent<String> event = new AuditablePayloadEvent<>(this, "xyz");
|
||||
ac.publishEvent(event);
|
||||
assertThat(ac.getBean(AuditableListener.class).events.contains(event)).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,6 +59,7 @@ public class PayloadApplicationEventTests {
|
|||
AuditablePayloadEvent<String> event = new AuditablePayloadEvent<>(this, "xyz");
|
||||
ac.publishEvent(event);
|
||||
assertThat(events.contains(event)).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,6 +76,7 @@ public class PayloadApplicationEventTests {
|
|||
AuditablePayloadEvent<String> event = new AuditablePayloadEvent<>(this, "xyz");
|
||||
ac.publishEvent(event);
|
||||
assertThat(events.contains(event.getPayload())).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -38,6 +38,7 @@ public class GroovyApplicationContextTests {
|
|||
Object framework = ctx.getBean("framework");
|
||||
assertThat(framework).as("could not find framework bean").isNotNull();
|
||||
assertThat(framework).isEqualTo("Grails");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,6 +54,7 @@ public class GroovyApplicationContextTests {
|
|||
Object company = ctx.getBean("company");
|
||||
assertThat(company).as("could not find company bean").isNotNull();
|
||||
assertThat(company).isEqualTo("SpringSource");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -68,6 +70,7 @@ public class GroovyApplicationContextTests {
|
|||
Object company = ctx.getBean("company");
|
||||
assertThat(company).as("could not find company bean").isNotNull();
|
||||
assertThat(company).isEqualTo("SpringSource");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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.
|
||||
|
@ -24,10 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Mark Fisher
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ApplicationContextLifecycleTests {
|
||||
class ApplicationContextLifecycleTests {
|
||||
|
||||
@Test
|
||||
public void testBeansStart() {
|
||||
void beansStart() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
|
@ -39,10 +39,11 @@ public class ApplicationContextLifecycleTests {
|
|||
assertThat(bean2.isRunning()).as(error).isTrue();
|
||||
assertThat(bean3.isRunning()).as(error).isTrue();
|
||||
assertThat(bean4.isRunning()).as(error).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeansStop() {
|
||||
void beansStop() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
|
@ -60,10 +61,11 @@ public class ApplicationContextLifecycleTests {
|
|||
assertThat(bean2.isRunning()).as(stopError).isFalse();
|
||||
assertThat(bean3.isRunning()).as(stopError).isFalse();
|
||||
assertThat(bean4.isRunning()).as(stopError).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartOrder() {
|
||||
void startOrder() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
|
@ -79,10 +81,11 @@ public class ApplicationContextLifecycleTests {
|
|||
assertThat(bean2.getStartOrder() > bean1.getStartOrder()).as(orderError).isTrue();
|
||||
assertThat(bean3.getStartOrder() > bean2.getStartOrder()).as(orderError).isTrue();
|
||||
assertThat(bean4.getStartOrder() > bean2.getStartOrder()).as(orderError).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopOrder() {
|
||||
void stopOrder() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
context.stop();
|
||||
|
@ -99,6 +102,7 @@ public class ApplicationContextLifecycleTests {
|
|||
assertThat(bean2.getStopOrder() < bean1.getStopOrder()).as(orderError).isTrue();
|
||||
assertThat(bean3.getStopOrder() < bean2.getStopOrder()).as(orderError).isTrue();
|
||||
assertThat(bean4.getStopOrder() < bean2.getStopOrder()).as(orderError).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -48,10 +48,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 02.10.2003
|
||||
*/
|
||||
public class BeanFactoryPostProcessorTests {
|
||||
class BeanFactoryPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void testRegisteredBeanFactoryPostProcessor() {
|
||||
void registeredBeanFactoryPostProcessor() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerSingleton("tb1", TestBean.class);
|
||||
ac.registerSingleton("tb2", TestBean.class);
|
||||
|
@ -60,10 +60,11 @@ public class BeanFactoryPostProcessorTests {
|
|||
assertThat(bfpp.wasCalled).isFalse();
|
||||
ac.refresh();
|
||||
assertThat(bfpp.wasCalled).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefinedBeanFactoryPostProcessor() {
|
||||
void definedBeanFactoryPostProcessor() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerSingleton("tb1", TestBean.class);
|
||||
ac.registerSingleton("tb2", TestBean.class);
|
||||
|
@ -71,11 +72,12 @@ public class BeanFactoryPostProcessorTests {
|
|||
ac.refresh();
|
||||
TestBeanFactoryPostProcessor bfpp = (TestBeanFactoryPostProcessor) ac.getBean("bfpp");
|
||||
assertThat(bfpp.wasCalled).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testMultipleDefinedBeanFactoryPostProcessors() {
|
||||
void multipleDefinedBeanFactoryPostProcessors() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerSingleton("tb1", TestBean.class);
|
||||
ac.registerSingleton("tb2", TestBean.class);
|
||||
|
@ -89,10 +91,11 @@ public class BeanFactoryPostProcessorTests {
|
|||
TestBeanFactoryPostProcessor bfpp = (TestBeanFactoryPostProcessor) ac.getBean("bfpp1");
|
||||
assertThat(bfpp.initValue).isEqualTo("value");
|
||||
assertThat(bfpp.wasCalled).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanFactoryPostProcessorNotExecutedByBeanFactory() {
|
||||
void beanFactoryPostProcessorNotExecutedByBeanFactory() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerBeanDefinition("tb1", new RootBeanDefinition(TestBean.class));
|
||||
bf.registerBeanDefinition("tb2", new RootBeanDefinition(TestBean.class));
|
||||
|
@ -102,7 +105,7 @@ public class BeanFactoryPostProcessorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionRegistryPostProcessor() {
|
||||
void beanDefinitionRegistryPostProcessor() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerSingleton("tb1", TestBean.class);
|
||||
ac.registerSingleton("tb2", TestBean.class);
|
||||
|
@ -114,10 +117,11 @@ public class BeanFactoryPostProcessorTests {
|
|||
assertThat(bdrpp.wasCalled).isTrue();
|
||||
assertThat(ac.getBean("bfpp1", TestBeanFactoryPostProcessor.class).wasCalled).isTrue();
|
||||
assertThat(ac.getBean("bfpp2", TestBeanFactoryPostProcessor.class).wasCalled).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionRegistryPostProcessorRegisteringAnother() {
|
||||
void beanDefinitionRegistryPostProcessorRegisteringAnother() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerSingleton("tb1", TestBean.class);
|
||||
ac.registerSingleton("tb2", TestBean.class);
|
||||
|
@ -125,10 +129,11 @@ public class BeanFactoryPostProcessorTests {
|
|||
ac.refresh();
|
||||
assertThat(ac.getBean("bfpp1", TestBeanFactoryPostProcessor.class).wasCalled).isTrue();
|
||||
assertThat(ac.getBean("bfpp2", TestBeanFactoryPostProcessor.class).wasCalled).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrioritizedBeanDefinitionRegistryPostProcessorRegisteringAnother() {
|
||||
void prioritizedBeanDefinitionRegistryPostProcessorRegisteringAnother() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerSingleton("tb1", TestBean.class);
|
||||
ac.registerSingleton("tb2", TestBean.class);
|
||||
|
@ -136,26 +141,27 @@ public class BeanFactoryPostProcessorTests {
|
|||
ac.refresh();
|
||||
assertThat(ac.getBean("bfpp1", TestBeanFactoryPostProcessor.class).wasCalled).isTrue();
|
||||
assertThat(ac.getBean("bfpp2", TestBeanFactoryPostProcessor.class).wasCalled).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanFactoryPostProcessorAsApplicationListener() {
|
||||
void beanFactoryPostProcessorAsApplicationListener() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
ac.registerBeanDefinition("bfpp", new RootBeanDefinition(ListeningBeanFactoryPostProcessor.class));
|
||||
ac.refresh();
|
||||
boolean condition = ac.getBean(ListeningBeanFactoryPostProcessor.class).received instanceof ContextRefreshedEvent;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(ac.getBean(ListeningBeanFactoryPostProcessor.class).received).isInstanceOf(ContextRefreshedEvent.class);
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanFactoryPostProcessorWithInnerBeanAsApplicationListener() {
|
||||
void beanFactoryPostProcessorWithInnerBeanAsApplicationListener() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(NestingBeanFactoryPostProcessor.class);
|
||||
rbd.getPropertyValues().add("listeningBean", new RootBeanDefinition(ListeningBean.class));
|
||||
ac.registerBeanDefinition("bfpp", rbd);
|
||||
ac.refresh();
|
||||
boolean condition = ac.getBean(NestingBeanFactoryPostProcessor.class).getListeningBean().received instanceof ContextRefreshedEvent;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(ac.getBean(NestingBeanFactoryPostProcessor.class).getListeningBean().received).isInstanceOf(ContextRefreshedEvent.class);
|
||||
ac.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -74,14 +74,14 @@ public class ClassPathXmlApplicationContextTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void testSingleConfigLocation() {
|
||||
void singleConfigLocation() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT);
|
||||
assertThat(ctx.containsBean("someMessageSource")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleConfigLocations() {
|
||||
void multipleConfigLocations() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
FQ_CONTEXT_B, FQ_CONTEXT_C, FQ_CONTEXT_A);
|
||||
assertThat(ctx.containsBean("service")).isTrue();
|
||||
|
@ -106,7 +106,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConfigLocationPattern() {
|
||||
void configLocationPattern() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
|
||||
assertThat(ctx.containsBean("service")).isTrue();
|
||||
assertThat(ctx.containsBean("logicOne")).isTrue();
|
||||
|
@ -117,28 +117,29 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSingleConfigLocationWithClass() {
|
||||
void singleConfigLocationWithClass() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(SIMPLE_CONTEXT, getClass());
|
||||
assertThat(ctx.containsBean("someMessageSource")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasWithPlaceholder() {
|
||||
void aliasWithPlaceholder() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
FQ_CONTEXT_B, FQ_ALIASED_CONTEXT_C, FQ_CONTEXT_A);
|
||||
assertThat(ctx.containsBean("service")).isTrue();
|
||||
assertThat(ctx.containsBean("logicOne")).isTrue();
|
||||
assertThat(ctx.containsBean("logicTwo")).isTrue();
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextWithInvalidValueType() throws IOException {
|
||||
void contextWithInvalidValueType() throws IOException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] {INVALID_VALUE_TYPE_CONTEXT}, false);
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
||||
context::refresh)
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(context::refresh)
|
||||
.satisfies(ex -> {
|
||||
assertThat(ex.contains(TypeMismatchException.class)).isTrue();
|
||||
assertThat(ex.toString()).contains("someMessageSource", "useCodeAsDefaultMessage");
|
||||
|
@ -146,6 +147,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
|
||||
assertThat(context.isActive()).isFalse();
|
||||
});
|
||||
context.close();
|
||||
}
|
||||
|
||||
private void checkExceptionFromInvalidValueType(Throwable ex) {
|
||||
|
@ -162,7 +164,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testContextWithInvalidLazyClass() {
|
||||
void contextWithInvalidLazyClass() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(INVALID_CLASS_CONTEXT, getClass());
|
||||
assertThat(ctx.containsBean("someMessageSource")).isTrue();
|
||||
assertThatExceptionOfType(CannotLoadBeanClassException.class).isThrownBy(() ->
|
||||
|
@ -172,7 +174,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testContextWithClassNameThatContainsPlaceholder() {
|
||||
void contextWithClassNameThatContainsPlaceholder() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CLASS_WITH_PLACEHOLDER_CONTEXT, getClass());
|
||||
assertThat(ctx.containsBean("someMessageSource")).isTrue();
|
||||
boolean condition = ctx.getBean("someMessageSource") instanceof StaticMessageSource;
|
||||
|
@ -181,7 +183,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleConfigLocationsWithClass() {
|
||||
void multipleConfigLocationsWithClass() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
new String[] {CONTEXT_B, CONTEXT_C, CONTEXT_A}, getClass());
|
||||
assertThat(ctx.containsBean("service")).isTrue();
|
||||
|
@ -191,7 +193,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBeanAndApplicationListener() {
|
||||
void factoryBeanAndApplicationListener() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
|
||||
ctx.getBeanFactory().registerSingleton("manualFBAAL", new FactoryBeanAndApplicationListener());
|
||||
assertThat(ctx.getBeansOfType(ApplicationListener.class).size()).isEqualTo(2);
|
||||
|
@ -199,7 +201,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSourceAware() {
|
||||
void messageSourceAware() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
|
||||
MessageSource messageSource = (MessageSource) ctx.getBean("messageSource");
|
||||
Service service1 = (Service) ctx.getBean("service");
|
||||
|
@ -214,7 +216,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testResourceArrayPropertyEditor() throws IOException {
|
||||
void resourceArrayPropertyEditor() throws IOException {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
|
||||
Service service = (Service) ctx.getBean("service");
|
||||
assertThat(service.getResources().length).isEqualTo(3);
|
||||
|
@ -226,17 +228,18 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testChildWithProxy() throws Exception {
|
||||
void childWithProxy() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
|
||||
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
|
||||
new String[] {CHILD_WITH_PROXY_CONTEXT}, ctx);
|
||||
assertThat(AopUtils.isAopProxy(child.getBean("assemblerOne"))).isTrue();
|
||||
assertThat(AopUtils.isAopProxy(child.getBean("assemblerTwo"))).isTrue();
|
||||
child.close();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasForParentContext() {
|
||||
void aliasForParentContext() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT);
|
||||
assertThat(ctx.containsBean("someMessageSource")).isTrue();
|
||||
|
||||
|
@ -272,7 +275,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAliasThatOverridesParent() {
|
||||
void aliasThatOverridesParent() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT);
|
||||
Object someMs = ctx.getBean("someMessageSource");
|
||||
|
||||
|
@ -286,7 +289,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAliasThatOverridesEarlierBean() {
|
||||
void aliasThatOverridesEarlierBean() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
FQ_SIMPLE_CONTEXT, ALIAS_THAT_OVERRIDES_PARENT_CONTEXT);
|
||||
Object myMs = ctx.getBean("myMessageSource");
|
||||
|
@ -324,7 +327,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testResourceAndInputStream() throws IOException {
|
||||
void resourceAndInputStream() throws IOException {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(RESOURCE_CONTEXT) {
|
||||
@Override
|
||||
public Resource getResource(String location) {
|
||||
|
@ -354,7 +357,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGenericApplicationContextWithXmlBeanDefinitions() {
|
||||
void genericApplicationContextWithXmlBeanDefinitions() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
||||
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
|
||||
|
@ -368,7 +371,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() {
|
||||
void genericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.setClassLoader(null);
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
||||
|
@ -385,7 +388,7 @@ public class ClassPathXmlApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
|
||||
void genericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.setId("testContext");
|
||||
ctx.setDisplayName("Test Context");
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Set;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
@ -41,10 +41,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ConversionServiceFactoryBeanTests {
|
||||
class ConversionServiceFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void createDefaultConversionService() {
|
||||
void createDefaultConversionService() {
|
||||
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
|
||||
factory.afterPropertiesSet();
|
||||
ConversionService service = factory.getObject();
|
||||
|
@ -52,7 +52,7 @@ public class ConversionServiceFactoryBeanTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void createDefaultConversionServiceWithSupplements() {
|
||||
void createDefaultConversionServiceWithSupplements() {
|
||||
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
|
||||
Set<Object> converters = new HashSet<>();
|
||||
converters.add(new Converter<String, Foo>() {
|
||||
|
@ -94,7 +94,7 @@ public class ConversionServiceFactoryBeanTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void createDefaultConversionServiceWithInvalidSupplements() {
|
||||
void createDefaultConversionServiceWithInvalidSupplements() {
|
||||
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
|
||||
Set<Object> converters = new HashSet<>();
|
||||
converters.add("bogus");
|
||||
|
@ -103,17 +103,17 @@ public class ConversionServiceFactoryBeanTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void conversionServiceInApplicationContext() {
|
||||
void conversionServiceInApplicationContext() {
|
||||
doTestConversionServiceInApplicationContext("conversionService.xml", ClassPathResource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conversionServiceInApplicationContextWithResourceOverriding() {
|
||||
void conversionServiceInApplicationContextWithResourceOverriding() {
|
||||
doTestConversionServiceInApplicationContext("conversionServiceWithResourceOverriding.xml", FileSystemResource.class);
|
||||
}
|
||||
|
||||
private void doTestConversionServiceInApplicationContext(String fileName, Class<?> resourceClass) {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass());
|
||||
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass());
|
||||
ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class);
|
||||
assertThat(resourceClass.isInstance(tb.getResource())).isTrue();
|
||||
assertThat(tb.getResourceArray().length > 0).isTrue();
|
||||
|
@ -123,21 +123,22 @@ public class ConversionServiceFactoryBeanTests {
|
|||
assertThat(tb.getResourceArrayMap().size() == 1).isTrue();
|
||||
assertThat(tb.getResourceArrayMap().get("key1").length > 0).isTrue();
|
||||
assertThat(resourceClass.isInstance(tb.getResourceArrayMap().get("key1")[0])).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
public static class Foo {
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
public static class Bar {
|
||||
static class Bar {
|
||||
}
|
||||
|
||||
public static class Baz {
|
||||
static class Baz {
|
||||
}
|
||||
|
||||
public static class ComplexConstructorArgument {
|
||||
static class ComplexConstructorArgument {
|
||||
|
||||
public ComplexConstructorArgument(Map<String, Class<?>> map) {
|
||||
ComplexConstructorArgument(Map<String, Class<?>> map) {
|
||||
assertThat(!map.isEmpty()).isTrue();
|
||||
assertThat(map.keySet().iterator().next()).isInstanceOf(String.class);
|
||||
assertThat(map.values().iterator().next()).isInstanceOf(Class.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -36,10 +36,10 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
|||
* @author Mark Fisher
|
||||
* @since 3.0
|
||||
*/
|
||||
public class DefaultLifecycleProcessorTests {
|
||||
class DefaultLifecycleProcessorTests {
|
||||
|
||||
@Test
|
||||
public void defaultLifecycleProcessorInstance() {
|
||||
void defaultLifecycleProcessorInstance() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.refresh();
|
||||
Object lifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
|
||||
|
@ -48,7 +48,7 @@ public class DefaultLifecycleProcessorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customLifecycleProcessorInstance() {
|
||||
void customLifecycleProcessorInstance() {
|
||||
BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
|
||||
beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
@ -63,7 +63,7 @@ public class DefaultLifecycleProcessorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void singleSmartLifecycleAutoStartup() throws Exception {
|
||||
void singleSmartLifecycleAutoStartup() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans);
|
||||
bean.setAutoStartup(true);
|
||||
|
@ -75,10 +75,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
context.stop();
|
||||
assertThat(bean.isRunning()).isFalse();
|
||||
assertThat(startedBeans.size()).isEqualTo(1);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleSmartLifecycleAutoStartupWithLazyInit() throws Exception {
|
||||
void singleSmartLifecycleAutoStartupWithLazyInit() throws Exception {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(DummySmartLifecycleBean.class);
|
||||
bd.setLazyInit(true);
|
||||
|
@ -88,10 +89,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean.isRunning()).isTrue();
|
||||
context.stop();
|
||||
assertThat(bean.isRunning()).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleSmartLifecycleAutoStartupWithLazyInitFactoryBean() throws Exception {
|
||||
void singleSmartLifecycleAutoStartupWithLazyInitFactoryBean() throws Exception {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(DummySmartLifecycleFactoryBean.class);
|
||||
bd.setLazyInit(true);
|
||||
|
@ -101,10 +103,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean.isRunning()).isTrue();
|
||||
context.stop();
|
||||
assertThat(bean.isRunning()).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleSmartLifecycleWithoutAutoStartup() throws Exception {
|
||||
void singleSmartLifecycleWithoutAutoStartup() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans);
|
||||
bean.setAutoStartup(false);
|
||||
|
@ -118,10 +121,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean.isRunning()).isTrue();
|
||||
assertThat(startedBeans.size()).isEqualTo(1);
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleSmartLifecycleAutoStartupWithNonAutoStartupDependency() throws Exception {
|
||||
void singleSmartLifecycleAutoStartupWithNonAutoStartupDependency() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans);
|
||||
bean.setAutoStartup(true);
|
||||
|
@ -140,10 +144,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean.isRunning()).isFalse();
|
||||
assertThat(dependency.isRunning()).isFalse();
|
||||
assertThat(startedBeans.size()).isEqualTo(1);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smartLifecycleGroupStartup() throws Exception {
|
||||
void smartLifecycleGroupStartup() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans);
|
||||
TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forStartupTests(1, startedBeans);
|
||||
|
@ -174,10 +179,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(2);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(3);
|
||||
assertThat(getPhase(startedBeans.get(4))).isEqualTo(Integer.MAX_VALUE);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextRefreshThenStartWithMixedBeans() throws Exception {
|
||||
void contextRefreshThenStartWithMixedBeans() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestLifecycleBean simpleBean1 = TestLifecycleBean.forStartupTests(startedBeans);
|
||||
TestLifecycleBean simpleBean2 = TestLifecycleBean.forStartupTests(startedBeans);
|
||||
|
@ -208,10 +214,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(startedBeans.size()).isEqualTo(4);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(0);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextRefreshThenStopAndRestartWithMixedBeans() throws Exception {
|
||||
void contextRefreshThenStopAndRestartWithMixedBeans() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestLifecycleBean simpleBean1 = TestLifecycleBean.forStartupTests(startedBeans);
|
||||
TestLifecycleBean simpleBean2 = TestLifecycleBean.forStartupTests(startedBeans);
|
||||
|
@ -249,11 +256,12 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(4))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(5))).isEqualTo(5);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void smartLifecycleGroupShutdown() throws Exception {
|
||||
void smartLifecycleGroupShutdown() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 300, stoppedBeans);
|
||||
TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(3, 100, stoppedBeans);
|
||||
|
@ -279,11 +287,12 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(2);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(6))).isEqualTo(1);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void singleSmartLifecycleShutdown() throws Exception {
|
||||
void singleSmartLifecycleShutdown() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean bean = TestSmartLifecycleBean.forShutdownTests(99, 300, stoppedBeans);
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
@ -294,10 +303,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(stoppedBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans.get(0)).isEqualTo(bean);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleLifecycleShutdown() throws Exception {
|
||||
void singleLifecycleShutdown() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
Lifecycle bean = new TestLifecycleBean(null, stoppedBeans);
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
@ -310,10 +320,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(stoppedBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans.get(0)).isEqualTo(bean);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mixedShutdown() throws Exception {
|
||||
void mixedShutdown() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
Lifecycle bean1 = TestLifecycleBean.forShutdownTests(stoppedBeans);
|
||||
Lifecycle bean2 = TestSmartLifecycleBean.forShutdownTests(500, 200, stoppedBeans);
|
||||
|
@ -358,10 +369,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(0);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(-1);
|
||||
assertThat(getPhase(stoppedBeans.get(6))).isEqualTo(Integer.MIN_VALUE);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dependencyStartedFirstEvenIfItsPhaseIsHigher() throws Exception {
|
||||
void dependencyStartedFirstEvenIfItsPhaseIsHigher() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans);
|
||||
TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forStartupTests(2, startedBeans);
|
||||
|
@ -386,11 +398,12 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(startedBeans.get(2)).isEqualTo(bean2);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(Integer.MAX_VALUE);
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void dependentShutdownFirstEvenIfItsPhaseIsLower() throws Exception {
|
||||
void dependentShutdownFirstEvenIfItsPhaseIsLower() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 100, stoppedBeans);
|
||||
TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans);
|
||||
|
@ -429,10 +442,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(7);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(Integer.MIN_VALUE);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dependencyStartedFirstAndIsSmartLifecycle() throws Exception {
|
||||
void dependencyStartedFirstAndIsSmartLifecycle() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forStartupTests(-99, startedBeans);
|
||||
TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forStartupTests(99, startedBeans);
|
||||
|
@ -459,11 +473,12 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(99);
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void dependentShutdownFirstAndIsSmartLifecycle() throws Exception {
|
||||
void dependentShutdownFirstAndIsSmartLifecycle() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 400, stoppedBeans);
|
||||
TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forShutdownTests(-99, 100, stoppedBeans);
|
||||
|
@ -501,10 +516,11 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(-99);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(0);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(Integer.MIN_VALUE);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dependencyStartedFirstButNotSmartLifecycle() throws Exception {
|
||||
void dependencyStartedFirstButNotSmartLifecycle() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans);
|
||||
TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forStartupTests(7, startedBeans);
|
||||
|
@ -523,11 +539,12 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(7);
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void dependentShutdownFirstButNotSmartLifecycle() throws Exception {
|
||||
void dependentShutdownFirstButNotSmartLifecycle() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
|
||||
TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans);
|
||||
TestLifecycleBean simpleBean = TestLifecycleBean.forShutdownTests(stoppedBeans);
|
||||
|
@ -561,6 +578,7 @@ public class DefaultLifecycleProcessorTests {
|
|||
assertThat(getPhase(stoppedBeans.get(2))).isEqualTo(2);
|
||||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(Integer.MIN_VALUE);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericApplicationContextTests {
|
||||
class GenericApplicationContextTests {
|
||||
|
||||
@Test
|
||||
void getBeanForClass() {
|
||||
|
@ -48,6 +48,7 @@ public class GenericApplicationContextTests {
|
|||
|
||||
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(() ->
|
||||
ac.getBean(Object.class));
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -60,6 +61,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(ac.getBean(String.class)).isSameAs(ac.getBean("testBean"));
|
||||
assertThat(ac.getBean(CharSequence.class)).isSameAs(ac.getBean("testBean"));
|
||||
assertThat(ac.getBean("testBean")).isEqualTo(ac.toString());
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,6 +75,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(ac.getBean(String.class)).isEqualTo(ac.getBean("testBean"));
|
||||
assertThat(ac.getBean(CharSequence.class)).isEqualTo(ac.getBean("testBean"));
|
||||
assertThat(ac.getBean("testBean")).isEqualTo(ac.toString());
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,6 +96,7 @@ public class GenericApplicationContextTests {
|
|||
ac.getAutowireCapableBeanFactory().getBean("testBean");
|
||||
ac.getAutowireCapableBeanFactory().getBean(String.class);
|
||||
});
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -106,6 +110,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean(BeanB.class));
|
||||
assertThat(context.getBean(BeanA.class).c).isSameAs(context.getBean(BeanC.class));
|
||||
assertThat(context.getBean(BeanB.class).applicationContext).isSameAs(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,6 +124,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(context.getBean("a", BeanA.class).b).isSameAs(context.getBean("b"));
|
||||
assertThat(context.getBean("a", BeanA.class).c).isSameAs(context.getBean("c"));
|
||||
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -137,6 +143,7 @@ public class GenericApplicationContextTests {
|
|||
|
||||
assertThat(context.getDefaultListableBeanFactory().getDependentBeans(BeanB.class.getName())).isEqualTo(new String[] {BeanA.class.getName()});
|
||||
assertThat(context.getDefaultListableBeanFactory().getDependentBeans(BeanC.class.getName())).isEqualTo(new String[] {BeanA.class.getName()});
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -153,6 +160,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean(BeanB.class));
|
||||
assertThat(context.getBean(BeanA.class).c).isSameAs(context.getBean(BeanC.class));
|
||||
assertThat(context.getBean(BeanB.class).applicationContext).isSameAs(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -168,6 +176,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean("b", BeanB.class));
|
||||
assertThat(context.getBean("a", BeanA.class).c).isSameAs(context.getBean("c"));
|
||||
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -184,6 +193,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean("b", BeanB.class));
|
||||
assertThat(context.getBean("a", BeanA.class).c).isSameAs(context.getBean("c"));
|
||||
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -200,6 +210,7 @@ public class GenericApplicationContextTests {
|
|||
assertThat(context.getBeansOfType(BeanA.class).isEmpty()).isTrue();
|
||||
assertThat(context.getBeansOfType(BeanB.class).values().iterator().next()).isSameAs(context.getBean(BeanB.class));
|
||||
assertThat(context.getBeansOfType(BeanC.class).values().iterator().next()).isSameAs(context.getBean(BeanC.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -208,6 +219,7 @@ public class GenericApplicationContextTests {
|
|||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.setApplicationStartup(applicationStartup);
|
||||
assertThat(context.getBeanFactory().getApplicationStartup()).isEqualTo(applicationStartup);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,12 +18,10 @@ package org.springframework.context.support;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GenericXmlApplicationContext}.
|
||||
*
|
||||
|
@ -31,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericXmlApplicationContextTests {
|
||||
class GenericXmlApplicationContextTests {
|
||||
|
||||
private static final Class<?> RELATIVE_CLASS = GenericXmlApplicationContextTests.class;
|
||||
private static final String RESOURCE_BASE_PATH = ClassUtils.classPackageAsResourcePath(RELATIVE_CLASS);
|
||||
|
@ -41,30 +39,35 @@ public class GenericXmlApplicationContextTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void classRelativeResourceLoading_ctor() {
|
||||
ApplicationContext ctx = new GenericXmlApplicationContext(RELATIVE_CLASS, RESOURCE_NAME);
|
||||
void classRelativeResourceLoading_ctor() {
|
||||
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(RELATIVE_CLASS, RESOURCE_NAME);
|
||||
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classRelativeResourceLoading_load() {
|
||||
void classRelativeResourceLoading_load() {
|
||||
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
|
||||
ctx.load(RELATIVE_CLASS, RESOURCE_NAME);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullyQualifiedResourceLoading_ctor() {
|
||||
ApplicationContext ctx = new GenericXmlApplicationContext(FQ_RESOURCE_PATH);
|
||||
void fullyQualifiedResourceLoading_ctor() {
|
||||
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(FQ_RESOURCE_PATH);
|
||||
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullyQualifiedResourceLoading_load() {
|
||||
void fullyQualifiedResourceLoading_load() {
|
||||
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
|
||||
ctx.load(FQ_RESOURCE_PATH);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -23,7 +23,6 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.beans.factory.config.PropertyResourceConfigurer;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
@ -35,7 +34,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
|
||||
/**
|
||||
* Integration tests for {@link PropertyResourceConfigurer} implementations requiring
|
||||
* interaction with an {@link ApplicationContext}. For example, a {@link PropertyPlaceholderConfigurer}
|
||||
* interaction with an {@link ApplicationContext}. For example, a
|
||||
* {@link org.springframework.beans.factory.config.PropertyPlaceholderConfigurer}
|
||||
* that contains ${..} tokens in its 'location' property requires being tested through an ApplicationContext
|
||||
* as opposed to using only a BeanFactory during testing.
|
||||
*
|
||||
|
@ -44,39 +44,41 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @see org.springframework.beans.factory.config.PropertyResourceConfigurerTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PropertyResourceConfigurerIntegrationTests {
|
||||
class PropertyResourceConfigurerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithSystemPropertyInLocation() {
|
||||
void propertyPlaceholderConfigurerWithSystemPropertyInLocation() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
|
||||
ac.registerSingleton("tb", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("location", "${user.dir}/test");
|
||||
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
|
||||
ac.registerSingleton("configurer", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class, pvs);
|
||||
String userDir = getUserDir();
|
||||
assertThatExceptionOfType(BeanInitializationException.class)
|
||||
.isThrownBy(ac::refresh)
|
||||
.withCauseInstanceOf(FileNotFoundException.class)
|
||||
.withMessageContaining(userDir);
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithSystemPropertiesInLocation() {
|
||||
void propertyPlaceholderConfigurerWithSystemPropertiesInLocation() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
|
||||
ac.registerSingleton("tb", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("location", "${user.dir}/test/${user.dir}");
|
||||
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
|
||||
ac.registerSingleton("configurer", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class, pvs);
|
||||
String userDir = getUserDir();
|
||||
assertThatExceptionOfType(BeanInitializationException.class)
|
||||
.isThrownBy(ac::refresh)
|
||||
.withCauseInstanceOf(FileNotFoundException.class)
|
||||
.matches(ex -> ex.getMessage().contains(userDir + "/test/" + userDir) ||
|
||||
ex.getMessage().contains(userDir + "/test//" + userDir));
|
||||
ac.close();
|
||||
}
|
||||
|
||||
private String getUserDir() {
|
||||
|
@ -89,57 +91,61 @@ public class PropertyResourceConfigurerIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithUnresolvableSystemPropertiesInLocation() {
|
||||
void propertyPlaceholderConfigurerWithUnresolvableSystemPropertiesInLocation() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
|
||||
ac.registerSingleton("tb", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("location", "${myprop}/test/${myprop}");
|
||||
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
|
||||
ac.registerSingleton("configurer", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class, pvs);
|
||||
assertThatExceptionOfType(BeanInitializationException.class)
|
||||
.isThrownBy(ac::refresh)
|
||||
.withMessageContaining("myprop");
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithMultiLevelCircularReference() {
|
||||
void propertyPlaceholderConfigurerWithMultiLevelCircularReference() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("name", "name${var}");
|
||||
ac.registerSingleton("tb1", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${var}");
|
||||
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
|
||||
ac.registerSingleton("configurer1", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class, pvs);
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh);
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithNestedCircularReference() {
|
||||
void propertyPlaceholderConfigurerWithNestedCircularReference() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("name", "name${var}");
|
||||
ac.registerSingleton("tb1", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m}");
|
||||
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
|
||||
ac.registerSingleton("configurer1", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class, pvs);
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh);
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithNestedUnresolvableReference() {
|
||||
void propertyPlaceholderConfigurerWithNestedUnresolvableReference() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("name", "name${var}");
|
||||
ac.registerSingleton("tb1", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m2}");
|
||||
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
|
||||
ac.registerSingleton("configurer1", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class, pvs);
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh);
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithValueFromSystemProperty() {
|
||||
void propertyPlaceholderConfigurerWithValueFromSystemProperty() {
|
||||
final String propertyName = getClass().getName() + ".test";
|
||||
|
||||
try {
|
||||
|
@ -155,11 +161,12 @@ public class PropertyResourceConfigurerIntegrationTests {
|
|||
pvs.addPropertyValue("target", new RuntimeBeanReference("tb"));
|
||||
context.registerSingleton("tbProxy", org.springframework.aop.framework.ProxyFactoryBean.class, pvs);
|
||||
|
||||
context.registerSingleton("configurer", PropertyPlaceholderConfigurer.class);
|
||||
context.registerSingleton("configurer", org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class);
|
||||
context.refresh();
|
||||
|
||||
TestBean testBean = context.getBean("tb", TestBean.class);
|
||||
assertThat(testBean.getTouchy()).isEqualTo("mytest");
|
||||
context.close();
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(propertyName);
|
||||
|
|
|
@ -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.
|
||||
|
@ -26,26 +26,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Scott Andrews
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Spr7283Tests {
|
||||
class Spr7283Tests {
|
||||
|
||||
@Test
|
||||
public void testListWithInconsistentElementType() {
|
||||
void listWithInconsistentElementTypes() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spr7283.xml", getClass());
|
||||
List<?> list = ctx.getBean("list", List.class);
|
||||
assertThat(list.size()).isEqualTo(2);
|
||||
boolean condition1 = list.get(0) instanceof A;
|
||||
assertThat(condition1).isTrue();
|
||||
boolean condition = list.get(1) instanceof B;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(list).hasSize(2);
|
||||
assertThat(list.get(0)).isInstanceOf(A.class);
|
||||
assertThat(list.get(1)).isInstanceOf(B.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
public static class A {
|
||||
public A() {}
|
||||
static class A {
|
||||
A() {}
|
||||
}
|
||||
|
||||
public static class B {
|
||||
public B() {}
|
||||
static class B {
|
||||
B() {}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -28,48 +28,49 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Spr7816Tests {
|
||||
class Spr7816Tests {
|
||||
|
||||
@Test
|
||||
public void spr7816() {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("spr7816.xml", getClass());
|
||||
void spr7816() {
|
||||
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("spr7816.xml", getClass());
|
||||
FilterAdapter adapter = ctx.getBean(FilterAdapter.class);
|
||||
assertThat(adapter.getSupportedTypes().get("Building")).isEqualTo(Building.class);
|
||||
assertThat(adapter.getSupportedTypes().get("Entrance")).isEqualTo(Entrance.class);
|
||||
assertThat(adapter.getSupportedTypes().get("Dwelling")).isEqualTo(Dwelling.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public static class FilterAdapter {
|
||||
static class FilterAdapter {
|
||||
|
||||
private String extensionPrefix;
|
||||
|
||||
private Map<String, Class<? extends DomainEntity>> supportedTypes;
|
||||
|
||||
public FilterAdapter(final String extensionPrefix, final Map<String, Class<? extends DomainEntity>> supportedTypes) {
|
||||
FilterAdapter(final String extensionPrefix, final Map<String, Class<? extends DomainEntity>> supportedTypes) {
|
||||
this.extensionPrefix = extensionPrefix;
|
||||
this.supportedTypes = supportedTypes;
|
||||
}
|
||||
|
||||
public String getExtensionPrefix() {
|
||||
String getExtensionPrefix() {
|
||||
return extensionPrefix;
|
||||
}
|
||||
|
||||
public Map<String, Class<? extends DomainEntity>> getSupportedTypes() {
|
||||
Map<String, Class<? extends DomainEntity>> getSupportedTypes() {
|
||||
return supportedTypes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Building extends DomainEntity {
|
||||
abstract static class DomainEntity {
|
||||
}
|
||||
|
||||
public static class Entrance extends DomainEntity {
|
||||
static final class Building extends DomainEntity {
|
||||
}
|
||||
|
||||
public static class Dwelling extends DomainEntity {
|
||||
static final class Entrance extends DomainEntity {
|
||||
}
|
||||
|
||||
public abstract static class DomainEntity {
|
||||
|
||||
static final class Dwelling extends DomainEntity {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -22,14 +22,11 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DateTimeFormatterFactoryBeanTests {
|
||||
|
||||
private final DateTimeFormatterFactoryBean factory = new DateTimeFormatterFactoryBean();
|
||||
|
|
|
@ -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.
|
||||
|
@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DateTimeFormatterFactoryTests {
|
||||
|
||||
// Potential test timezone, both have daylight savings on October 21st
|
||||
|
|
|
@ -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.
|
||||
|
@ -53,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class JodaTimeFormattingTests {
|
||||
|
||||
private FormattingConversionService conversionService;
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.springframework.beans.ConfigurablePropertyAccessor;
|
|||
import org.springframework.beans.PropertyAccessorFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
@ -49,9 +48,6 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
|||
import org.springframework.format.Formatter;
|
||||
import org.springframework.format.Printer;
|
||||
import org.springframework.format.annotation.NumberFormat;
|
||||
import org.springframework.format.datetime.joda.DateTimeParser;
|
||||
import org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory;
|
||||
import org.springframework.format.datetime.joda.ReadablePartialPrinter;
|
||||
import org.springframework.format.number.NumberStyleFormatter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -91,6 +87,7 @@ public class FormattingConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void formatFieldForTypeWithPrinterParserWithCoercion() {
|
||||
formattingService.addConverter(new Converter<DateTime, LocalDate>() {
|
||||
@Override
|
||||
|
@ -98,8 +95,9 @@ public class FormattingConversionServiceTests {
|
|||
return source.toLocalDate();
|
||||
}
|
||||
});
|
||||
formattingService.addFormatterForFieldType(LocalDate.class, new ReadablePartialPrinter(DateTimeFormat
|
||||
.shortDate()), new DateTimeParser(DateTimeFormat.shortDate()));
|
||||
formattingService.addFormatterForFieldType(LocalDate.class,
|
||||
new org.springframework.format.datetime.joda.ReadablePartialPrinter(DateTimeFormat.shortDate()),
|
||||
new org.springframework.format.datetime.joda.DateTimeParser(DateTimeFormat.shortDate()));
|
||||
String formatted = formattingService.convert(new LocalDate(2009, 10, 31), String.class);
|
||||
assertThat(formatted).isEqualTo("10/31/09");
|
||||
LocalDate date = formattingService.convert("10/31/09", LocalDate.class);
|
||||
|
@ -118,14 +116,14 @@ public class FormattingConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
@SuppressWarnings({ "resource", "deprecation" })
|
||||
public void formatFieldForValueInjectionUsingMetaAnnotations() {
|
||||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(MetaValueBean.class);
|
||||
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
ac.registerBeanDefinition("valueBean", bd);
|
||||
ac.registerBeanDefinition("conversionService", new RootBeanDefinition(FormattingConversionServiceFactoryBean.class));
|
||||
ac.registerBeanDefinition("ppc", new RootBeanDefinition(PropertyPlaceholderConfigurer.class));
|
||||
ac.registerBeanDefinition("ppc", new RootBeanDefinition(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class));
|
||||
ac.refresh();
|
||||
System.setProperty("myDate", "10-31-09");
|
||||
System.setProperty("myNumber", "99.99%");
|
||||
|
@ -141,22 +139,25 @@ public class FormattingConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void formatFieldForAnnotation() throws Exception {
|
||||
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
formattingService.addFormatterForFieldAnnotation(new org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
doTestFormatFieldForAnnotation(Model.class, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void formatFieldForAnnotationWithDirectFieldAccess() throws Exception {
|
||||
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
formattingService.addFormatterForFieldAnnotation(new org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
doTestFormatFieldForAnnotation(Model.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
@SuppressWarnings({ "resource", "deprecation" })
|
||||
public void formatFieldForAnnotationWithPlaceholders() throws Exception {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc =
|
||||
new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
|
||||
Properties props = new Properties();
|
||||
props.setProperty("dateStyle", "S-");
|
||||
props.setProperty("datePattern", "M-d-yy");
|
||||
|
@ -164,15 +165,16 @@ public class FormattingConversionServiceTests {
|
|||
context.getBeanFactory().registerSingleton("ppc", ppc);
|
||||
context.refresh();
|
||||
context.getBeanFactory().initializeBean(formattingService, "formattingService");
|
||||
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
formattingService.addFormatterForFieldAnnotation(new org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
doTestFormatFieldForAnnotation(ModelWithPlaceholders.class, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
@SuppressWarnings({ "resource", "deprecation" })
|
||||
public void formatFieldForAnnotationWithPlaceholdersAndFactoryBean() throws Exception {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc =
|
||||
new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
|
||||
Properties props = new Properties();
|
||||
props.setProperty("dateStyle", "S-");
|
||||
props.setProperty("datePattern", "M-d-yy");
|
||||
|
@ -296,8 +298,9 @@ public class FormattingConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void formatFieldForAnnotationWithSubclassAsFieldType() throws Exception {
|
||||
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory() {
|
||||
formattingService.addFormatterForFieldAnnotation(new org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory() {
|
||||
@Override
|
||||
public Printer<?> getPrinter(org.springframework.format.annotation.DateTimeFormat annotation, Class<?> fieldType) {
|
||||
assertThat(fieldType).isEqualTo(MyDate.class);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue