diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPointTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPointTests.java index 67d3250005..13c911c334 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPointTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPointTests.java @@ -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,54 +67,50 @@ 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 { - JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint(); - assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue(); - // Ensure that these don't cause problems - jp.toShortString(); - jp.toLongString(); - - assertThat(AbstractAspectJAdvice.currentJoinPoint().getTarget()).isSameAs(target); - assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())).isFalse(); - - ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis(); - assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())).isTrue(); - - assertThat(thisProxy).isNotSameAs(target); - - // Check getting again doesn't cause a problem - assertThat(AbstractAspectJAdvice.currentJoinPoint().getThis()).isSameAs(thisProxy); - - // Try reentrant call--will go through this advice. - // Be sure to increment depth to avoid infinite recursion - if (depth++ == 0) { - // Check that toString doesn't cause a problem - thisProxy.toString(); - // Change age, so this will be returned by invocation - thisProxy.setAge(newAge); - assertThat(thisProxy.getAge()).isEqualTo(newAge); - } - - assertThat(thisProxy).isSameAs(AopContext.currentProxy()); - assertThat(raw).isSameAs(target); - - assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()).isSameAs(method.getName()); - assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()).isEqualTo(method.getModifiers()); - - MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature(); - assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature()).as("Return same MethodSignature repeatedly").isSameAs(msig); - assertThat(AbstractAspectJAdvice.currentJoinPoint()).as("Return same JoinPoint repeatedly").isSameAs(AbstractAspectJAdvice.currentJoinPoint()); - assertThat(msig.getDeclaringType()).isEqualTo(method.getDeclaringClass()); - assertThat(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())).isTrue(); - assertThat(msig.getReturnType()).isEqualTo(method.getReturnType()); - assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue(); - msig.toLongString(); - msig.toShortString(); + 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 + jp.toShortString(); + jp.toLongString(); + + assertThat(AbstractAspectJAdvice.currentJoinPoint().getTarget()).isSameAs(target); + assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())).isFalse(); + + ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis(); + assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())).isTrue(); + + assertThat(thisProxy).isNotSameAs(target); + + // Check getting again doesn't cause a problem + assertThat(AbstractAspectJAdvice.currentJoinPoint().getThis()).isSameAs(thisProxy); + + // Try reentrant call--will go through this advice. + // Be sure to increment depth to avoid infinite recursion + if (depth.getAndIncrement() == 0) { + // Check that toString doesn't cause a problem + thisProxy.toString(); + // Change age, so this will be returned by invocation + thisProxy.setAge(newAge); + assertThat(thisProxy.getAge()).isEqualTo(newAge); } + + assertThat(thisProxy).isSameAs(AopContext.currentProxy()); + assertThat(raw).isSameAs(target); + + assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()).isSameAs(method.getName()); + assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()).isEqualTo(method.getModifiers()); + + MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature(); + assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature()).as("Return same MethodSignature repeatedly").isSameAs(msig); + assertThat(AbstractAspectJAdvice.currentJoinPoint()).as("Return same JoinPoint repeatedly").isSameAs(AbstractAspectJAdvice.currentJoinPoint()); + assertThat(msig.getDeclaringType()).isEqualTo(method.getDeclaringClass()); + assertThat(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())).isTrue(); + assertThat(msig.getReturnType()).isEqualTo(method.getReturnType()); + assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue(); + msig.toLongString(); + msig.toShortString(); }); ITestBean itb = (ITestBean) pf.getProxy(); // Any call will do diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java index 60f89f8401..9de8bd658c 100644 --- a/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java @@ -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 is = new LinkedList<>(); - is.add((MethodInterceptor) invocation -> returnValue); - ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, null, //? - m, null, null, is // list - ); + Object returnValue = new Object(); + List 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 is = new LinkedList<>(); + List 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. diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/NullPrimitiveTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/NullPrimitiveTests.java index 7289908eac..047e84b3d7 100644 --- a/spring-aop/src/test/java/org/springframework/aop/framework/NullPrimitiveTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/framework/NullPrimitiveTests.java @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; */ public class NullPrimitiveTests { - static interface Foo { + interface Foo { int getValue(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java index 66cf8e471e..af695751d1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java @@ -182,4 +182,5 @@ public class ViewResolverRegistry { getViewResolver(); } } + }