Polishing
This commit is contained in:
@@ -85,7 +85,7 @@ import static org.assertj.core.api.Assertions.assertThatRuntimeException;
|
||||
* @author Chris Beams
|
||||
* @since 13.03.2003
|
||||
*/
|
||||
public abstract class AbstractAopProxyTests {
|
||||
abstract class AbstractAopProxyTests {
|
||||
|
||||
protected final MockTargetSource mockTargetSource = new MockTargetSource();
|
||||
|
||||
@@ -125,7 +125,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* Simple test that if we set values we can get them out again.
|
||||
*/
|
||||
@Test
|
||||
void testValuesStick() {
|
||||
void valuesStick() {
|
||||
int age1 = 33;
|
||||
int age2 = 37;
|
||||
String name = "tony";
|
||||
@@ -146,7 +146,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializationAdviceAndTargetNotSerializable() throws Exception {
|
||||
void serializationAdviceAndTargetNotSerializable() throws Exception {
|
||||
TestBean tb = new TestBean();
|
||||
assertThat(SerializationTestUtils.isSerializable(tb)).isFalse();
|
||||
|
||||
@@ -159,7 +159,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializationAdviceNotSerializable() throws Exception {
|
||||
void serializationAdviceNotSerializable() throws Exception {
|
||||
SerializablePerson sp = new SerializablePerson();
|
||||
assertThat(SerializationTestUtils.isSerializable(sp)).isTrue();
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializableTargetAndAdvice() throws Throwable {
|
||||
void serializableTargetAndAdvice() throws Throwable {
|
||||
SerializablePerson personTarget = new SerializablePerson();
|
||||
personTarget.setName("jim");
|
||||
personTarget.setAge(26);
|
||||
@@ -245,7 +245,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* Check also proxy exposure.
|
||||
*/
|
||||
@Test
|
||||
void testOneAdvisedObjectCallsAnother() {
|
||||
void oneAdvisedObjectCallsAnother() {
|
||||
int age1 = 33;
|
||||
int age2 = 37;
|
||||
|
||||
@@ -290,7 +290,7 @@ public abstract class AbstractAopProxyTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testReentrance() {
|
||||
void reentrance() {
|
||||
int age1 = 33;
|
||||
|
||||
TestBean target1 = new TestBean();
|
||||
@@ -314,7 +314,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTargetCanGetProxy() {
|
||||
void targetCanGetProxy() {
|
||||
NopInterceptor di = new NopInterceptor();
|
||||
INeedsToSeeProxy target = new TargetChecker();
|
||||
ProxyFactory proxyFactory = new ProxyFactory(target);
|
||||
@@ -338,7 +338,7 @@ public abstract class AbstractAopProxyTests {
|
||||
|
||||
@Test
|
||||
// Should fail to get proxy as exposeProxy wasn't set to true
|
||||
public void testTargetCantGetProxyByDefault() {
|
||||
public void targetCantGetProxyByDefault() {
|
||||
NeedsToSeeProxy et = new NeedsToSeeProxy();
|
||||
ProxyFactory pf1 = new ProxyFactory(et);
|
||||
assertThat(pf1.isExposeProxy()).isFalse();
|
||||
@@ -347,12 +347,12 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testContext() {
|
||||
void context() {
|
||||
testContext(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoContext() {
|
||||
void noContext() {
|
||||
testContext(false);
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* target returns {@code this}
|
||||
*/
|
||||
@Test
|
||||
void testTargetReturnsThis() {
|
||||
void targetReturnsThis() {
|
||||
// Test return value
|
||||
TestBean raw = new OwnSpouse();
|
||||
|
||||
@@ -406,7 +406,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeclaredException() {
|
||||
void declaredException() {
|
||||
final Exception expectedException = new Exception();
|
||||
// Test return value
|
||||
MethodInterceptor mi = invocation -> {
|
||||
@@ -434,7 +434,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* org.springframework.cglib UndeclaredThrowableException
|
||||
*/
|
||||
@Test
|
||||
void testUndeclaredCheckedException() {
|
||||
void undeclaredCheckedException() {
|
||||
final Exception unexpectedException = new Exception();
|
||||
// Test return value
|
||||
MethodInterceptor mi = invocation -> {
|
||||
@@ -454,7 +454,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUndeclaredUncheckedException() {
|
||||
void undeclaredUncheckedException() {
|
||||
final RuntimeException unexpectedException = new RuntimeException();
|
||||
// Test return value
|
||||
MethodInterceptor mi = invocation -> {
|
||||
@@ -480,7 +480,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* so as to guarantee a consistent programming model.
|
||||
*/
|
||||
@Test
|
||||
void testTargetCanGetInvocationEvenIfNoAdviceChain() {
|
||||
void targetCanGetInvocationEvenIfNoAdviceChain() {
|
||||
NeedsToSeeProxy target = new NeedsToSeeProxy();
|
||||
AdvisedSupport pc = new AdvisedSupport(INeedsToSeeProxy.class);
|
||||
pc.setTarget(target);
|
||||
@@ -494,7 +494,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTargetCanGetInvocation() {
|
||||
void targetCanGetInvocation() {
|
||||
final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean();
|
||||
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class);
|
||||
@@ -527,7 +527,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* Test stateful interceptor
|
||||
*/
|
||||
@Test
|
||||
void testMixinWithIntroductionAdvisor() {
|
||||
void mixinWithIntroductionAdvisor() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory();
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -538,7 +538,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMixinWithIntroductionInfo() {
|
||||
void mixinWithIntroductionInfo() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory();
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -571,7 +571,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReplaceArgument() {
|
||||
void replaceArgument() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory();
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -592,7 +592,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCanCastProxyToProxyConfig() {
|
||||
void canCastProxyToProxyConfig() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory(tb);
|
||||
NopInterceptor di = new NopInterceptor();
|
||||
@@ -628,7 +628,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAdviceImplementsIntroductionInfo() {
|
||||
void adviceImplementsIntroductionInfo() {
|
||||
TestBean tb = new TestBean();
|
||||
String name = "tony";
|
||||
tb.setName(name);
|
||||
@@ -645,7 +645,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCannotAddDynamicIntroductionAdviceExceptInIntroductionAdvice() {
|
||||
void cannotAddDynamicIntroductionAdviceExceptInIntroductionAdvice() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -658,7 +658,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() {
|
||||
void rejectsBogusDynamicIntroductionAdviceWithNoAdapter() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -679,7 +679,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* that are unsupported by the IntroductionInterceptor.
|
||||
*/
|
||||
@Test
|
||||
void testCannotAddIntroductionAdviceWithUnimplementedInterface() {
|
||||
void cannotAddIntroductionAdviceWithUnimplementedInterface() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -695,7 +695,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* as it's constrained by the interface.
|
||||
*/
|
||||
@Test
|
||||
void testIntroductionThrowsUncheckedException() {
|
||||
void introductionThrowsUncheckedException() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -720,7 +720,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* Should only be able to introduce interfaces, not classes.
|
||||
*/
|
||||
@Test
|
||||
void testCannotAddIntroductionAdviceToIntroduceClass() {
|
||||
void cannotAddIntroductionAdviceToIntroduceClass() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -733,7 +733,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCannotAddInterceptorWhenFrozen() {
|
||||
void cannotAddInterceptorWhenFrozen() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -753,7 +753,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* Check that casting to Advised can't get around advice freeze.
|
||||
*/
|
||||
@Test
|
||||
void testCannotAddAdvisorWhenFrozenUsingCast() {
|
||||
void cannotAddAdvisorWhenFrozenUsingCast() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -773,7 +773,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCannotRemoveAdvisorWhenFrozen() {
|
||||
void cannotRemoveAdvisorWhenFrozen() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
@@ -798,7 +798,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUseAsHashKey() {
|
||||
void useAsHashKey() {
|
||||
TestBean target1 = new TestBean();
|
||||
ProxyFactory pf1 = new ProxyFactory(target1);
|
||||
pf1.addAdvice(new NopInterceptor());
|
||||
@@ -823,7 +823,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* Check that the string is informative.
|
||||
*/
|
||||
@Test
|
||||
void testProxyConfigString() {
|
||||
void proxyConfigString() {
|
||||
TestBean target = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
pc.setInterfaces(ITestBean.class);
|
||||
@@ -839,7 +839,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCanPreventCastToAdvisedUsingOpaque() {
|
||||
void canPreventCastToAdvisedUsingOpaque() {
|
||||
TestBean target = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
pc.setInterfaces(ITestBean.class);
|
||||
@@ -860,7 +860,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAdviceSupportListeners() {
|
||||
void adviceSupportListeners() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(21);
|
||||
|
||||
@@ -899,7 +899,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExistingProxyChangesTarget() {
|
||||
void existingProxyChangesTarget() {
|
||||
TestBean tb1 = new TestBean();
|
||||
tb1.setAge(33);
|
||||
|
||||
@@ -942,7 +942,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDynamicMethodPointcutThatAlwaysAppliesStatically() {
|
||||
void dynamicMethodPointcutThatAlwaysAppliesStatically() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory();
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -959,7 +959,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() {
|
||||
void dynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory();
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -982,7 +982,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStaticMethodPointcut() {
|
||||
void staticMethodPointcut() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory();
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -1004,7 +1004,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* We can do this if we clone the invocation.
|
||||
*/
|
||||
@Test
|
||||
void testCloneInvocationToProceedThreeTimes() {
|
||||
void cloneInvocationToProceedThreeTimes() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory(tb);
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -1041,7 +1041,7 @@ public abstract class AbstractAopProxyTests {
|
||||
* We want to change the arguments on a clone: it shouldn't affect the original.
|
||||
*/
|
||||
@Test
|
||||
void testCanChangeArgumentsIndependentlyOnClonedInvocation() {
|
||||
void canChangeArgumentsIndependentlyOnClonedInvocation() {
|
||||
TestBean tb = new TestBean();
|
||||
ProxyFactory pc = new ProxyFactory(tb);
|
||||
pc.addInterface(ITestBean.class);
|
||||
@@ -1085,7 +1085,7 @@ public abstract class AbstractAopProxyTests {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
void testOverloadedMethodsWithDifferentAdvice() {
|
||||
void overloadedMethodsWithDifferentAdvice() {
|
||||
Overloads target = new Overloads();
|
||||
ProxyFactory pc = new ProxyFactory(target);
|
||||
|
||||
@@ -1121,7 +1121,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyIsBoundBeforeTargetSourceInvoked() {
|
||||
void proxyIsBoundBeforeTargetSourceInvoked() {
|
||||
final TestBean target = new TestBean();
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
pf.addAdvice(new DebugInterceptor());
|
||||
@@ -1147,7 +1147,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
void equals() {
|
||||
IOther a = new AllInstancesAreEqual();
|
||||
IOther b = new AllInstancesAreEqual();
|
||||
NopInterceptor i1 = new NopInterceptor();
|
||||
@@ -1177,7 +1177,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeforeAdvisorIsInvoked() {
|
||||
void beforeAdvisorIsInvoked() {
|
||||
CountingBeforeAdvice cba = new CountingBeforeAdvice();
|
||||
@SuppressWarnings("serial")
|
||||
Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cba) {
|
||||
@@ -1206,7 +1206,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUserAttributes() {
|
||||
void userAttributes() {
|
||||
class MapAwareMethodInterceptor implements MethodInterceptor {
|
||||
private final Map<String, String> expectedValues;
|
||||
private final Map<String, String> valuesToAdd;
|
||||
@@ -1257,7 +1257,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultiAdvice() {
|
||||
void multiAdvice() {
|
||||
CountingMultiAdvice cca = new CountingMultiAdvice();
|
||||
@SuppressWarnings("serial")
|
||||
Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) {
|
||||
@@ -1291,7 +1291,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeforeAdviceThrowsException() {
|
||||
void beforeAdviceThrowsException() {
|
||||
final RuntimeException rex = new RuntimeException();
|
||||
@SuppressWarnings("serial")
|
||||
CountingBeforeAdvice ba = new CountingBeforeAdvice() {
|
||||
@@ -1333,7 +1333,7 @@ public abstract class AbstractAopProxyTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testAfterReturningAdvisorIsInvoked() {
|
||||
void afterReturningAdvisorIsInvoked() {
|
||||
class SummingAfterAdvice implements AfterReturningAdvice {
|
||||
public int sum;
|
||||
@Override
|
||||
@@ -1370,7 +1370,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAfterReturningAdvisorIsNotInvokedOnException() {
|
||||
void afterReturningAdvisorIsNotInvokedOnException() {
|
||||
CountingAfterReturningAdvice car = new CountingAfterReturningAdvice();
|
||||
TestBean target = new TestBean();
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
@@ -1392,7 +1392,7 @@ public abstract class AbstractAopProxyTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testThrowsAdvisorIsInvoked() {
|
||||
void throwsAdvisorIsInvoked() {
|
||||
// Reacts to ServletException and RemoteException
|
||||
MyThrowsHandler th = new MyThrowsHandler();
|
||||
@SuppressWarnings("serial")
|
||||
@@ -1425,7 +1425,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddThrowsAdviceWithoutAdvisor() {
|
||||
void addThrowsAdviceWithoutAdvisor() {
|
||||
// Reacts to ServletException and RemoteException
|
||||
MyThrowsHandler th = new MyThrowsHandler();
|
||||
|
||||
@@ -1850,26 +1850,17 @@ public abstract class AbstractAopProxyTests {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#getTargetClass()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getTargetClass() {
|
||||
return target.getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#getTarget()
|
||||
*/
|
||||
@Override
|
||||
public Object getTarget() {
|
||||
++gets;
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void releaseTarget(Object pTarget) {
|
||||
if (pTarget != this.target) {
|
||||
@@ -1879,8 +1870,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that gets and releases match
|
||||
*
|
||||
* Check that gets and releases match.
|
||||
*/
|
||||
public void verify() {
|
||||
if (gets != releases) {
|
||||
|
||||
@@ -78,13 +78,13 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testNullConfig() {
|
||||
void nullConfig() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CglibAopProxy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoTarget() {
|
||||
void noTarget() {
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||
pc.addAdvice(new NopInterceptor());
|
||||
AopProxy aop = createAopProxy(pc);
|
||||
@@ -92,7 +92,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProtectedMethodInvocation() {
|
||||
void protectedMethodInvocation() {
|
||||
ProtectedMethodTestBean bean = new ProtectedMethodTestBean();
|
||||
bean.value = "foo";
|
||||
mockTargetSource.setTarget(bean);
|
||||
@@ -109,7 +109,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPackageMethodInvocation() {
|
||||
void packageMethodInvocation() {
|
||||
PackageMethodTestBean bean = new PackageMethodTestBean();
|
||||
bean.value = "foo";
|
||||
mockTargetSource.setTarget(bean);
|
||||
@@ -126,7 +126,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyCanBeClassNotInterface() {
|
||||
void proxyCanBeClassNotInterface() {
|
||||
TestBean raw = new TestBean();
|
||||
raw.setAge(32);
|
||||
mockTargetSource.setTarget(raw);
|
||||
@@ -144,7 +144,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodInvocationDuringConstructor() {
|
||||
void methodInvocationDuringConstructor() {
|
||||
CglibTestBean bean = new CglibTestBean();
|
||||
bean.setName("Rob Harrop");
|
||||
|
||||
@@ -158,7 +158,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToStringInvocation() {
|
||||
void toStringInvocation() {
|
||||
PrivateCglibTestBean bean = new PrivateCglibTestBean();
|
||||
bean.setName("Rob Harrop");
|
||||
|
||||
@@ -172,7 +172,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnadvisedProxyCreationWithCallDuringConstructor() {
|
||||
void unadvisedProxyCreationWithCallDuringConstructor() {
|
||||
CglibTestBean target = new CglibTestBean();
|
||||
target.setName("Rob Harrop");
|
||||
|
||||
@@ -187,7 +187,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleProxies() {
|
||||
void multipleProxies() {
|
||||
TestBean target = new TestBean();
|
||||
target.setAge(20);
|
||||
TestBean target2 = new TestBean();
|
||||
@@ -233,7 +233,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleProxiesForIntroductionAdvisor() {
|
||||
void multipleProxiesForIntroductionAdvisor() {
|
||||
TestBean target1 = new TestBean();
|
||||
target1.setAge(20);
|
||||
TestBean target2 = new TestBean();
|
||||
@@ -257,7 +257,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithNoArgConstructor() {
|
||||
void withNoArgConstructor() {
|
||||
NoArgCtorTestBean target = new NoArgCtorTestBean("b", 1);
|
||||
target.reset();
|
||||
|
||||
@@ -272,7 +272,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyAProxy() {
|
||||
void proxyAProxy() {
|
||||
ITestBean target = new TestBean();
|
||||
|
||||
mockTargetSource.setTarget(target);
|
||||
@@ -293,7 +293,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyAProxyWithAdditionalInterface() {
|
||||
void proxyAProxyWithAdditionalInterface() {
|
||||
ITestBean target = new TestBean();
|
||||
mockTargetSource.setTarget(target);
|
||||
|
||||
@@ -351,7 +351,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExceptionHandling() {
|
||||
void exceptionHandling() {
|
||||
ExceptionThrower bean = new ExceptionThrower();
|
||||
mockTargetSource.setTarget(bean);
|
||||
|
||||
@@ -374,14 +374,14 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithDependencyChecking() {
|
||||
void withDependencyChecking() {
|
||||
try (ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass())) {
|
||||
ctx.getBean("testBean");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddAdviceAtRuntime() {
|
||||
void addAdviceAtRuntime() {
|
||||
TestBean bean = new TestBean();
|
||||
CountingBeforeAdvice cba = new CountingBeforeAdvice();
|
||||
|
||||
@@ -403,7 +403,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyProtectedMethod() {
|
||||
void proxyProtectedMethod() {
|
||||
CountingBeforeAdvice advice = new CountingBeforeAdvice();
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
|
||||
proxyFactory.addAdvice(advice);
|
||||
@@ -415,14 +415,14 @@ class CglibProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyTargetClassInCaseOfNoInterfaces() {
|
||||
void proxyTargetClassInCaseOfNoInterfaces() {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
|
||||
MyBean proxy = (MyBean) proxyFactory.getProxy();
|
||||
assertThat(proxy.add(1, 3)).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test // SPR-13328
|
||||
void testVarargsWithEnumArray() {
|
||||
void varargsWithEnumArray() {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
|
||||
MyBean proxy = (MyBean) proxyFactory.getProxy();
|
||||
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
|
||||
|
||||
@@ -53,12 +53,12 @@ class JdkDynamicProxyTests extends AbstractAopProxyTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testNullConfig() {
|
||||
void nullConfig() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new JdkDynamicAopProxy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyIsJustInterface() {
|
||||
void proxyIsJustInterface() {
|
||||
TestBean raw = new TestBean();
|
||||
raw.setAge(32);
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||
@@ -66,12 +66,11 @@ class JdkDynamicProxyTests extends AbstractAopProxyTests {
|
||||
JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc);
|
||||
|
||||
Object proxy = aop.getProxy();
|
||||
assertThat(proxy instanceof ITestBean).isTrue();
|
||||
assertThat(proxy instanceof TestBean).isFalse();
|
||||
assertThat(proxy).isInstanceOf(ITestBean.class).isNotInstanceOf(TestBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInterceptorIsInvokedWithNoTarget() {
|
||||
void interceptorIsInvokedWithNoTarget() {
|
||||
// Test return value
|
||||
final int age = 25;
|
||||
MethodInterceptor mi = (invocation -> age);
|
||||
@@ -85,12 +84,14 @@ class JdkDynamicProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTargetCanGetInvocationWithPrivateClass() {
|
||||
void targetCanGetInvocationWithPrivateClass() {
|
||||
final ExposedInvocationTestBean expectedTarget = new ExposedInvocationTestBean() {
|
||||
@Override
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertThat(invocation.getThis()).isEqualTo(this);
|
||||
assertThat(invocation.getMethod().getDeclaringClass()).as("Invocation should be on ITestBean: " + invocation.getMethod()).isEqualTo(ITestBean.class);
|
||||
assertThat(invocation.getMethod().getDeclaringClass())
|
||||
.as("Invocation should be on ITestBean: " + invocation.getMethod())
|
||||
.isEqualTo(ITestBean.class);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -113,7 +114,7 @@ class JdkDynamicProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProxyNotWrappedIfIncompatible() {
|
||||
void proxyNotWrappedIfIncompatible() {
|
||||
FooBar bean = new FooBar();
|
||||
ProxyCreatorSupport as = new ProxyCreatorSupport();
|
||||
as.setInterfaces(Foo.class);
|
||||
@@ -125,22 +126,22 @@ class JdkDynamicProxyTests extends AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsAndHashCodeDefined() {
|
||||
void equalsAndHashCodeDefined() {
|
||||
Named named = new Person();
|
||||
AdvisedSupport as = new AdvisedSupport(Named.class);
|
||||
as.setTarget(named);
|
||||
|
||||
Named proxy = (Named) new JdkDynamicAopProxy(as).getProxy();
|
||||
assertThat(proxy).isEqualTo(named);
|
||||
assertThat(named.hashCode()).isEqualTo(proxy.hashCode());
|
||||
assertThat(named).hasSameHashCodeAs(proxy);
|
||||
|
||||
proxy = (Named) new JdkDynamicAopProxy(as).getProxy();
|
||||
assertThat(proxy).isEqualTo(named);
|
||||
assertThat(named.hashCode()).isEqualTo(proxy.hashCode());
|
||||
assertThat(named).hasSameHashCodeAs(proxy);
|
||||
}
|
||||
|
||||
@Test // SPR-13328
|
||||
void testVarargsWithEnumArray() {
|
||||
void varargsWithEnumArray() {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new VarargTestBean());
|
||||
VarargTestInterface proxy = (VarargTestInterface) proxyFactory.getProxy();
|
||||
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.aop.target.ThreadLocalTargetSource;
|
||||
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
|
||||
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.testfixture.mixin.Lockable;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.testfixture.beans.CountingTestBean;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -40,48 +39,36 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* Tests for auto proxy creation by advisor recognition.
|
||||
*
|
||||
* @see org.springframework.aop.framework.autoproxy.AdvisorAutoProxyCreatorIntegrationTests
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Dave Syer
|
||||
* @author Chris Beams
|
||||
* @see org.springframework.aop.framework.autoproxy.AdvisorAutoProxyCreatorIntegrationTests
|
||||
*/
|
||||
class AdvisorAutoProxyCreatorTests {
|
||||
|
||||
private static final Class<?> CLASS = AdvisorAutoProxyCreatorTests.class;
|
||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
||||
|
||||
private static final String DEFAULT_CONTEXT = CLASSNAME + "-context.xml";
|
||||
private static final String CLASSNAME = AdvisorAutoProxyCreatorTests.class.getSimpleName();
|
||||
private static final String COMMON_INTERCEPTORS_CONTEXT = CLASSNAME + "-common-interceptors.xml";
|
||||
private static final String CUSTOM_TARGETSOURCE_CONTEXT = CLASSNAME + "-custom-targetsource.xml";
|
||||
private static final String QUICK_TARGETSOURCE_CONTEXT = CLASSNAME + "-quick-targetsource.xml";
|
||||
private static final String OPTIMIZED_CONTEXT = CLASSNAME + "-optimized.xml";
|
||||
|
||||
|
||||
/**
|
||||
* Return a bean factory with attributes and EnterpriseServices configured.
|
||||
*/
|
||||
protected BeanFactory getBeanFactory() {
|
||||
return new ClassPathXmlApplicationContext(DEFAULT_CONTEXT, CLASS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that we can provide a common interceptor that will
|
||||
* appear in the chain before "specific" interceptors,
|
||||
* which are sourced from matching advisors
|
||||
*/
|
||||
@Test
|
||||
void testCommonInterceptorAndAdvisor() {
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext(COMMON_INTERCEPTORS_CONTEXT, CLASS);
|
||||
ITestBean test1 = (ITestBean) bf.getBean("test1");
|
||||
void commonInterceptorAndAdvisor() {
|
||||
ClassPathXmlApplicationContext ctx = context(COMMON_INTERCEPTORS_CONTEXT);
|
||||
ITestBean test1 = (ITestBean) ctx.getBean("test1");
|
||||
assertThat(AopUtils.isAopProxy(test1)).isTrue();
|
||||
|
||||
Lockable lockable1 = (Lockable) test1;
|
||||
NopInterceptor nop1 = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
NopInterceptor nop2 = (NopInterceptor) bf.getBean("pointcutAdvisor", Advisor.class).getAdvice();
|
||||
NopInterceptor nop1 = (NopInterceptor) ctx.getBean("nopInterceptor");
|
||||
NopInterceptor nop2 = (NopInterceptor) ctx.getBean("pointcutAdvisor", Advisor.class).getAdvice();
|
||||
|
||||
ITestBean test2 = (ITestBean) bf.getBean("test2");
|
||||
ITestBean test2 = (ITestBean) ctx.getBean("test2");
|
||||
Lockable lockable2 = (Lockable) test2;
|
||||
|
||||
// Locking should be independent; nop is shared
|
||||
@@ -97,19 +84,19 @@ class AdvisorAutoProxyCreatorTests {
|
||||
assertThat(nop1.getCount()).isEqualTo(5);
|
||||
assertThat(nop2.getCount()).isEqualTo(0);
|
||||
|
||||
PackageVisibleMethod packageVisibleMethod = (PackageVisibleMethod) bf.getBean("packageVisibleMethod");
|
||||
PackageVisibleMethod packageVisibleMethod = (PackageVisibleMethod) ctx.getBean("packageVisibleMethod");
|
||||
assertThat(nop1.getCount()).isEqualTo(5);
|
||||
assertThat(nop2.getCount()).isEqualTo(0);
|
||||
packageVisibleMethod.doSomething();
|
||||
assertThat(nop1.getCount()).isEqualTo(6);
|
||||
assertThat(nop2.getCount()).isEqualTo(1);
|
||||
boolean condition = packageVisibleMethod instanceof Lockable;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(packageVisibleMethod).isInstanceOf(Lockable.class);
|
||||
Lockable lockable3 = (Lockable) packageVisibleMethod;
|
||||
lockable3.lock();
|
||||
assertThat(lockable3.locked()).isTrue();
|
||||
lockable3.unlock();
|
||||
assertThat(lockable3.locked()).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,107 +104,108 @@ class AdvisorAutoProxyCreatorTests {
|
||||
* hence no proxying, for this bean
|
||||
*/
|
||||
@Test
|
||||
void testCustomTargetSourceNoMatch() {
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
void customTargetSourceNoMatch() {
|
||||
ClassPathXmlApplicationContext ctx = context(CUSTOM_TARGETSOURCE_CONTEXT);
|
||||
ITestBean test = (ITestBean) ctx.getBean("test");
|
||||
assertThat(AopUtils.isAopProxy(test)).isFalse();
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomPrototypeTargetSource() {
|
||||
void customPrototypeTargetSource() {
|
||||
CountingTestBean.count = 0;
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
|
||||
ITestBean test = (ITestBean) bf.getBean("prototypeTest");
|
||||
ClassPathXmlApplicationContext ctx = context(CUSTOM_TARGETSOURCE_CONTEXT);
|
||||
ITestBean test = (ITestBean) ctx.getBean("prototypeTest");
|
||||
assertThat(AopUtils.isAopProxy(test)).isTrue();
|
||||
Advised advised = (Advised) test;
|
||||
boolean condition = advised.getTargetSource() instanceof PrototypeTargetSource;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(advised.getTargetSource()).isInstanceOf(PrototypeTargetSource.class);
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
// Check that references survived prototype creation
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
assertThat(CountingTestBean.count).as("Only 2 CountingTestBeans instantiated").isEqualTo(2);
|
||||
CountingTestBean.count = 0;
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLazyInitTargetSource() {
|
||||
void lazyInitTargetSource() {
|
||||
CountingTestBean.count = 0;
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
|
||||
ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
|
||||
ClassPathXmlApplicationContext ctx = context(CUSTOM_TARGETSOURCE_CONTEXT);
|
||||
ITestBean test = (ITestBean) ctx.getBean("lazyInitTest");
|
||||
assertThat(AopUtils.isAopProxy(test)).isTrue();
|
||||
Advised advised = (Advised) test;
|
||||
boolean condition = advised.getTargetSource() instanceof LazyInitTargetSource;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(advised.getTargetSource()).isInstanceOf(LazyInitTargetSource.class);
|
||||
assertThat(CountingTestBean.count).as("No CountingTestBean instantiated yet").isEqualTo(0);
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
assertThat(CountingTestBean.count).as("Only 1 CountingTestBean instantiated").isEqualTo(1);
|
||||
CountingTestBean.count = 0;
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQuickTargetSourceCreator() {
|
||||
ClassPathXmlApplicationContext bf =
|
||||
new ClassPathXmlApplicationContext(QUICK_TARGETSOURCE_CONTEXT, CLASS);
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
void quickTargetSourceCreator() {
|
||||
ClassPathXmlApplicationContext ctx = context(QUICK_TARGETSOURCE_CONTEXT);
|
||||
ITestBean test = (ITestBean) ctx.getBean("test");
|
||||
assertThat(AopUtils.isAopProxy(test)).isFalse();
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
// Check that references survived pooling
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
|
||||
// Now test the pooled one
|
||||
test = (ITestBean) bf.getBean(":test");
|
||||
test = (ITestBean) ctx.getBean(":test");
|
||||
assertThat(AopUtils.isAopProxy(test)).isTrue();
|
||||
Advised advised = (Advised) test;
|
||||
boolean condition2 = advised.getTargetSource() instanceof CommonsPool2TargetSource;
|
||||
assertThat(condition2).isTrue();
|
||||
assertThat(advised.getTargetSource()).isInstanceOf(CommonsPool2TargetSource.class);
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
// Check that references survived pooling
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
|
||||
// Now test the ThreadLocal one
|
||||
test = (ITestBean) bf.getBean("%test");
|
||||
test = (ITestBean) ctx.getBean("%test");
|
||||
assertThat(AopUtils.isAopProxy(test)).isTrue();
|
||||
advised = (Advised) test;
|
||||
boolean condition1 = advised.getTargetSource() instanceof ThreadLocalTargetSource;
|
||||
assertThat(condition1).isTrue();
|
||||
assertThat(advised.getTargetSource()).isInstanceOf(ThreadLocalTargetSource.class);
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
// Check that references survived pooling
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
|
||||
// Now test the Prototype TargetSource
|
||||
test = (ITestBean) bf.getBean("!test");
|
||||
test = (ITestBean) ctx.getBean("!test");
|
||||
assertThat(AopUtils.isAopProxy(test)).isTrue();
|
||||
advised = (Advised) test;
|
||||
boolean condition = advised.getTargetSource() instanceof PrototypeTargetSource;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(advised.getTargetSource()).isInstanceOf(PrototypeTargetSource.class);
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
// Check that references survived pooling
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
|
||||
|
||||
ITestBean test2 = (ITestBean) bf.getBean("!test");
|
||||
ITestBean test2 = (ITestBean) ctx.getBean("!test");
|
||||
assertThat(test).as("Prototypes cannot be the same object").isNotSameAs(test2);
|
||||
assertThat(test2.getName()).isEqualTo("Rod");
|
||||
assertThat(test2.getSpouse().getName()).isEqualTo("Kerry");
|
||||
bf.close();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithOptimizedProxy() {
|
||||
BeanFactory beanFactory = new ClassPathXmlApplicationContext(OPTIMIZED_CONTEXT, CLASS);
|
||||
void withOptimizedProxy() {
|
||||
ClassPathXmlApplicationContext ctx = context(OPTIMIZED_CONTEXT);
|
||||
|
||||
ITestBean testBean = (ITestBean) beanFactory.getBean("optimizedTestBean");
|
||||
ITestBean testBean = (ITestBean) ctx.getBean("optimizedTestBean");
|
||||
assertThat(AopUtils.isAopProxy(testBean)).isTrue();
|
||||
|
||||
CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) beanFactory.getBean("countingAdvice");
|
||||
|
||||
testBean.setAge(23);
|
||||
testBean.getAge();
|
||||
|
||||
CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) ctx.getBean("countingAdvice");
|
||||
assertThat(beforeAdvice.getCalls()).as("Incorrect number of calls to proxy").isEqualTo(2);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
private ClassPathXmlApplicationContext context(String filename) {
|
||||
return new ClassPathXmlApplicationContext(filename, getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class AutoProxyCreatorTests {
|
||||
|
||||
@Test
|
||||
void testBeanNameAutoProxyCreator() {
|
||||
void beanNameAutoProxyCreator() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testInterceptor", TestInterceptor.class);
|
||||
|
||||
@@ -105,10 +105,12 @@ class AutoProxyCreatorTests {
|
||||
assertThat(ti.nrOfInvocations).isEqualTo(6);
|
||||
tb2.getAge();
|
||||
assertThat(ti.nrOfInvocations).isEqualTo(7);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanNameAutoProxyCreatorWithFactoryBeanProxy() {
|
||||
void beanNameAutoProxyCreatorWithFactoryBeanProxy() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testInterceptor", TestInterceptor.class);
|
||||
|
||||
@@ -139,12 +141,14 @@ class AutoProxyCreatorTests {
|
||||
assertThat(ti.nrOfInvocations).isEqualTo((initialNr + 3));
|
||||
tb.getAge();
|
||||
assertThat(ti.nrOfInvocations).isEqualTo((initialNr + 3));
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomAutoProxyCreator() {
|
||||
void customAutoProxyCreator() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("autoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("noInterfaces", NoInterfaces.class);
|
||||
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
|
||||
sac.registerSingleton("singletonNoInterceptor", TestBean.class);
|
||||
@@ -166,7 +170,7 @@ class AutoProxyCreatorTests {
|
||||
assertThat(AopUtils.isCglibProxy(singletonToBeProxied)).isTrue();
|
||||
assertThat(AopUtils.isCglibProxy(prototypeToBeProxied)).isTrue();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
singletonNoInterceptor.getName();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
@@ -174,12 +178,14 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
|
||||
prototypeToBeProxied.getSpouse();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithFallbackToTargetClass() {
|
||||
void autoProxyCreatorWithFallbackToTargetClass() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", FallbackTestAutoProxyCreator.class);
|
||||
sac.registerSingleton("autoProxyCreator", FallbackTestAutoProxyCreator.class);
|
||||
sac.registerSingleton("noInterfaces", NoInterfaces.class);
|
||||
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
|
||||
sac.registerSingleton("singletonNoInterceptor", TestBean.class);
|
||||
@@ -201,7 +207,7 @@ class AutoProxyCreatorTests {
|
||||
assertThat(AopUtils.isCglibProxy(singletonToBeProxied)).isFalse();
|
||||
assertThat(AopUtils.isCglibProxy(prototypeToBeProxied)).isFalse();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
singletonNoInterceptor.getName();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
@@ -209,15 +215,17 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
|
||||
prototypeToBeProxied.getSpouse();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithFallbackToDynamicProxy() {
|
||||
void autoProxyCreatorWithFallbackToDynamicProxy() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("proxyFactoryBean", "false");
|
||||
sac.registerSingleton("testAutoProxyCreator", IntroductionTestAutoProxyCreator.class, pvs);
|
||||
sac.registerSingleton("autoProxyCreator", IntroductionTestAutoProxyCreator.class, pvs);
|
||||
|
||||
sac.registerSingleton("noInterfaces", NoInterfaces.class);
|
||||
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
|
||||
@@ -241,7 +249,7 @@ class AutoProxyCreatorTests {
|
||||
assertThat(AopUtils.isCglibProxy(singletonToBeProxied)).isFalse();
|
||||
assertThat(AopUtils.isCglibProxy(prototypeToBeProxied)).isFalse();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
singletonNoInterceptor.getName();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
@@ -249,16 +257,18 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
prototypeToBeProxied.getSpouse();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(4);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithPackageVisibleMethod() {
|
||||
void autoProxyCreatorWithPackageVisibleMethod() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("autoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("packageVisibleMethodToBeProxied", PackageVisibleMethod.class);
|
||||
sac.refresh();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
PackageVisibleMethod tb = (PackageVisibleMethod) sac.getBean("packageVisibleMethodToBeProxied");
|
||||
@@ -266,16 +276,18 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
tb.doSomething();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithFactoryBean() {
|
||||
void autoProxyCreatorWithFactoryBean() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("autoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class);
|
||||
sac.refresh();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
|
||||
@@ -286,12 +298,14 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
tb.getAge();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(3);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithFactoryBeanAndPrototype() {
|
||||
void autoProxyCreatorWithFactoryBeanAndPrototype() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
sac.registerSingleton("autoProxyCreator", TestAutoProxyCreator.class);
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("singleton", "false");
|
||||
@@ -299,7 +313,7 @@ class AutoProxyCreatorTests {
|
||||
|
||||
sac.refresh();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
|
||||
@@ -310,21 +324,23 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
tb.getAge();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(3);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithFactoryBeanAndProxyObjectOnly() {
|
||||
void autoProxyCreatorWithFactoryBeanAndProxyObjectOnly() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("proxyFactoryBean", "false");
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class, pvs);
|
||||
sac.registerSingleton("autoProxyCreator", TestAutoProxyCreator.class, pvs);
|
||||
|
||||
sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class);
|
||||
|
||||
sac.refresh();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
|
||||
@@ -341,15 +357,17 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
|
||||
tb2.getAge();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly() {
|
||||
void autoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("proxyObject", "false");
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class, pvs);
|
||||
sac.registerSingleton("autoProxyCreator", TestAutoProxyCreator.class, pvs);
|
||||
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("singleton", "false");
|
||||
@@ -357,7 +375,7 @@ class AutoProxyCreatorTests {
|
||||
|
||||
sac.refresh();
|
||||
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("autoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
|
||||
@@ -368,6 +386,8 @@ class AutoProxyCreatorTests {
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
tb.getAge();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
|
||||
sac.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.lang.reflect.Method;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.beans.testfixture.beans.Pet;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -38,17 +38,16 @@ class BeanNameAutoProxyCreatorInitTests {
|
||||
|
||||
@Test
|
||||
void ignoreAdvisorThatIsCurrentlyInCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
TestBean bean = ctx.getBean(TestBean.class);
|
||||
bean.setName("foo");
|
||||
assertThat(bean.getName()).isEqualTo("foo");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> bean.setName(null))
|
||||
.withMessage("Null argument at position 0");
|
||||
|
||||
ctx.close();
|
||||
String path = getClass().getSimpleName() + "-context.xml";
|
||||
try (ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(path, getClass())) {
|
||||
Pet pet = ctx.getBean(Pet.class);
|
||||
assertThat(pet.getName()).isEqualTo("Simba");
|
||||
pet.setName("Tiger");
|
||||
assertThat(pet.getName()).isEqualTo("Tiger");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> pet.setName(null))
|
||||
.withMessage("Null argument at position 0");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,8 +76,7 @@ class BeanNameAutoProxyCreatorTests {
|
||||
int age = 5;
|
||||
tb.setAge(age);
|
||||
assertThat(tb.getAge()).isEqualTo(age);
|
||||
boolean condition = tb instanceof TimeStamped;
|
||||
assertThat(condition).as("Introduction was made").isTrue();
|
||||
assertThat(tb).as("Introduction was made").isInstanceOf(TimeStamped.class);
|
||||
assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0);
|
||||
assertThat(nop.getCount()).isEqualTo(3);
|
||||
assertThat(tb.getName()).isEqualTo("introductionUsingJdk");
|
||||
@@ -98,8 +97,9 @@ class BeanNameAutoProxyCreatorTests {
|
||||
// Can still mod second object
|
||||
tb2.setAge(12);
|
||||
// But can't mod first
|
||||
assertThatExceptionOfType(LockedException.class).as("mixin should have locked this object").isThrownBy(() ->
|
||||
tb.setAge(6));
|
||||
assertThatExceptionOfType(LockedException.class)
|
||||
.as("mixin should have locked this object")
|
||||
.isThrownBy(() -> tb.setAge(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,8 +131,9 @@ class BeanNameAutoProxyCreatorTests {
|
||||
// Can still mod second object
|
||||
tb2.setAge(12);
|
||||
// But can't mod first
|
||||
assertThatExceptionOfType(LockedException.class).as("mixin should have locked this object").isThrownBy(() ->
|
||||
tb.setAge(6));
|
||||
assertThatExceptionOfType(LockedException.class)
|
||||
.as("mixin should have locked this object")
|
||||
.isThrownBy(() -> tb.setAge(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user