Polishing
This commit is contained in:
parent
d357ef706f
commit
f8f3067419
|
|
@ -17,8 +17,8 @@
|
|||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.JoinPoint.StaticPart;
|
||||
|
|
@ -33,7 +33,6 @@ import org.springframework.aop.framework.AopContext;
|
|||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
|
|
@ -51,14 +50,12 @@ public class MethodInvocationProceedingJoinPointTests {
|
|||
|
||||
@Test
|
||||
public void testingBindingWithJoinPoint() {
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
AbstractAspectJAdvice::currentJoinPoint);
|
||||
assertThatIllegalStateException().isThrownBy(AbstractAspectJAdvice::currentJoinPoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testingBindingWithProceedingJoinPoint() {
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
AbstractAspectJAdvice::currentJoinPoint);
|
||||
assertThatIllegalStateException().isThrownBy(AbstractAspectJAdvice::currentJoinPoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -70,11 +67,8 @@ public class MethodInvocationProceedingJoinPointTests {
|
|||
ProxyFactory pf = new ProxyFactory(raw);
|
||||
pf.setExposeProxy(true);
|
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
|
||||
pf.addAdvice(new MethodBeforeAdvice() {
|
||||
private int depth;
|
||||
|
||||
@Override
|
||||
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
|
||||
AtomicInteger depth = new AtomicInteger();
|
||||
pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
|
||||
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
|
||||
assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue();
|
||||
// Ensure that these don't cause problems
|
||||
|
|
@ -94,7 +88,7 @@ public class MethodInvocationProceedingJoinPointTests {
|
|||
|
||||
// Try reentrant call--will go through this advice.
|
||||
// Be sure to increment depth to avoid infinite recursion
|
||||
if (depth++ == 0) {
|
||||
if (depth.getAndIncrement() == 0) {
|
||||
// Check that toString doesn't cause a problem
|
||||
thisProxy.toString();
|
||||
// Change age, so this will be returned by invocation
|
||||
|
|
@ -117,7 +111,6 @@ public class MethodInvocationProceedingJoinPointTests {
|
|||
assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue();
|
||||
msig.toLongString();
|
||||
msig.toShortString();
|
||||
}
|
||||
});
|
||||
ITestBean itb = (ITestBean) pf.getProxy();
|
||||
// Any call will do
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.aop.framework;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
|
|
@ -32,39 +32,35 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Chris Beams
|
||||
* @since 14.03.2003
|
||||
*/
|
||||
public class MethodInvocationTests {
|
||||
class MethodInvocationTests {
|
||||
|
||||
@Test
|
||||
public void testValidInvocation() throws Throwable {
|
||||
Method m = Object.class.getMethod("hashCode");
|
||||
void testValidInvocation() throws Throwable {
|
||||
Method method = Object.class.getMethod("hashCode");
|
||||
Object proxy = new Object();
|
||||
final Object returnValue = new Object();
|
||||
List<Object> is = new LinkedList<>();
|
||||
is.add((MethodInterceptor) invocation -> returnValue);
|
||||
ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, null, //?
|
||||
m, null, null, is // list
|
||||
);
|
||||
Object returnValue = new Object();
|
||||
List<Object> interceptors = Collections.singletonList((MethodInterceptor) invocation -> returnValue);
|
||||
ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, null, method, null, null, interceptors);
|
||||
Object rv = invocation.proceed();
|
||||
assertThat(rv == returnValue).as("correct response").isTrue();
|
||||
assertThat(rv).as("correct response").isSameAs(returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* toString on target can cause failure.
|
||||
*/
|
||||
@Test
|
||||
public void testToStringDoesntHitTarget() throws Throwable {
|
||||
void testToStringDoesntHitTarget() throws Throwable {
|
||||
Object target = new TestBean() {
|
||||
@Override
|
||||
public String toString() {
|
||||
throw new UnsupportedOperationException("toString");
|
||||
}
|
||||
};
|
||||
List<Object> is = new LinkedList<>();
|
||||
List<Object> interceptors = Collections.emptyList();
|
||||
|
||||
Method m = Object.class.getMethod("hashCode");
|
||||
Object proxy = new Object();
|
||||
ReflectiveMethodInvocation invocation =
|
||||
new ReflectiveMethodInvocation(proxy, target, m, null, null, is);
|
||||
ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, target, m, null, null, interceptors);
|
||||
|
||||
// If it hits target, the test will fail with the UnsupportedOpException
|
||||
// in the inner class above.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
*/
|
||||
public class NullPrimitiveTests {
|
||||
|
||||
static interface Foo {
|
||||
interface Foo {
|
||||
int getValue();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -182,4 +182,5 @@ public class ViewResolverRegistry {
|
|||
getViewResolver();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue