Browse Source

Polish

pull/31970/head
Stéphane Nicoll 2 years ago
parent
commit
2a43cc7574
  1. 62
      spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java
  2. 9
      spring-aop/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutMatchingTests.java
  3. 16
      spring-aop/src/test/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPointTests.java
  4. 25
      spring-aop/src/test/java/org/springframework/aop/aspectj/TrickyAspectJPointcutExpressionTests.java
  5. 2
      spring-aop/src/test/java/org/springframework/aop/aspectj/TypePatternClassFilterTests.java
  6. 12
      spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java
  7. 6
      spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java
  8. 18
      spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java
  9. 29
      spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java
  10. 14
      spring-aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java
  11. 24
      spring-aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparatorTests.java
  12. 8
      spring-aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java
  13. 14
      spring-aop/src/test/java/org/springframework/aop/framework/NullPrimitiveTests.java
  14. 8
      spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java
  15. 46
      spring-aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java
  16. 17
      spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java
  17. 14
      spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java
  18. 5
      spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java
  19. 6
      spring-aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java
  20. 10
      spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java
  21. 6
      spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java
  22. 14
      spring-aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java
  23. 6
      spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java
  24. 10
      spring-aop/src/test/java/org/springframework/aop/scope/DefaultScopedObjectTests.java
  25. 8
      spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java
  26. 14
      spring-aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java
  27. 21
      spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java
  28. 4
      spring-aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java
  29. 19
      spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java
  30. 16
      spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java
  31. 18
      spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java
  32. 10
      spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java
  33. 6
      spring-aop/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceProxyTests.java
  34. 12
      spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java
  35. 6
      spring-aop/src/test/java/org/springframework/aop/target/LazyCreationTargetSourceTests.java
  36. 14
      spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java
  37. 6
      spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java
  38. 14
      spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java
  39. 10
      spring-aop/src/test/java/org/springframework/aop/target/dynamic/RefreshableTargetSourceTests.java
  40. 31
      spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/aspectj/CommonExpressions.java

62
spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java

@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Chris Beams * @author Chris Beams
* @author Yanming Zhou * @author Yanming Zhou
*/ */
public class AspectJExpressionPointcutTests { class AspectJExpressionPointcutTests {
public static final String MATCH_ALL_METHODS = "execution(* *(..))"; public static final String MATCH_ALL_METHODS = "execution(* *(..))";
@ -78,7 +78,7 @@ public class AspectJExpressionPointcutTests {
@Test @Test
public void testMatchExplicit() { void testMatchExplicit() {
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())";
Pointcut pointcut = getPointcut(expression); Pointcut pointcut = getPointcut(expression);
@ -96,7 +96,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testMatchWithTypePattern() throws Exception { void testMatchWithTypePattern() {
String expression = "execution(* *..TestBean.*Age(..))"; String expression = "execution(* *..TestBean.*Age(..))";
Pointcut pointcut = getPointcut(expression); Pointcut pointcut = getPointcut(expression);
@ -115,12 +115,12 @@ public class AspectJExpressionPointcutTests {
@Test @Test
public void testThis() throws SecurityException, NoSuchMethodException{ void testThis() throws SecurityException, NoSuchMethodException{
testThisOrTarget("this"); testThisOrTarget("this");
} }
@Test @Test
public void testTarget() throws SecurityException, NoSuchMethodException { void testTarget() throws SecurityException, NoSuchMethodException {
testThisOrTarget("target"); testThisOrTarget("target");
} }
@ -144,12 +144,12 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testWithinRootPackage() throws SecurityException, NoSuchMethodException { void testWithinRootPackage() throws SecurityException, NoSuchMethodException {
testWithinPackage(false); testWithinPackage(false);
} }
@Test @Test
public void testWithinRootAndSubpackages() throws SecurityException, NoSuchMethodException { void testWithinRootAndSubpackages() throws SecurityException, NoSuchMethodException {
testWithinPackage(true); testWithinPackage(true);
} }
@ -173,7 +173,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testFriendlyErrorOnNoLocationClassMatching() { void testFriendlyErrorOnNoLocationClassMatching() {
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
pc.matches(ITestBean.class)) pc.matches(ITestBean.class))
@ -181,7 +181,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testFriendlyErrorOnNoLocation2ArgMatching() { void testFriendlyErrorOnNoLocation2ArgMatching() {
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
pc.matches(getAge, ITestBean.class)) pc.matches(getAge, ITestBean.class))
@ -189,7 +189,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testFriendlyErrorOnNoLocation3ArgMatching() { void testFriendlyErrorOnNoLocation3ArgMatching() {
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
pc.matches(getAge, ITestBean.class, (Object[]) null)) pc.matches(getAge, ITestBean.class, (Object[]) null))
@ -198,7 +198,7 @@ public class AspectJExpressionPointcutTests {
@Test @Test
public void testMatchWithArgs() throws Exception { void testMatchWithArgs() throws Exception {
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)"; String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)";
Pointcut pointcut = getPointcut(expression); Pointcut pointcut = getPointcut(expression);
@ -217,7 +217,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testSimpleAdvice() { void testSimpleAdvice() {
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())";
CallCountingInterceptor interceptor = new CallCountingInterceptor(); CallCountingInterceptor interceptor = new CallCountingInterceptor();
TestBean testBean = getAdvisedProxy(expression, interceptor); TestBean testBean = getAdvisedProxy(expression, interceptor);
@ -230,7 +230,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testDynamicMatchingProxy() { void testDynamicMatchingProxy() {
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)"; String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)";
CallCountingInterceptor interceptor = new CallCountingInterceptor(); CallCountingInterceptor interceptor = new CallCountingInterceptor();
TestBean testBean = getAdvisedProxy(expression, interceptor); TestBean testBean = getAdvisedProxy(expression, interceptor);
@ -244,7 +244,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testInvalidExpression() { void testInvalidExpression() {
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)"; String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)";
assertThatIllegalArgumentException().isThrownBy(getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution assertThatIllegalArgumentException().isThrownBy(getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
} }
@ -274,7 +274,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testWithUnsupportedPointcutPrimitive() { void testWithUnsupportedPointcutPrimitive() {
String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())";
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class) assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class)
.isThrownBy(() -> getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution... .isThrownBy(() -> getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
@ -282,14 +282,14 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAndSubstitution() { void testAndSubstitution() {
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String)"); AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String)");
String expr = pc.getPointcutExpression().getPointcutExpression(); String expr = pc.getPointcutExpression().getPointcutExpression();
assertThat(expr).isEqualTo("execution(* *(..)) && args(String)"); assertThat(expr).isEqualTo("execution(* *(..)) && args(String)");
} }
@Test @Test
public void testMultipleAndSubstitutions() { void testMultipleAndSubstitutions() {
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)"); AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
String expr = pc.getPointcutExpression().getPointcutExpression(); String expr = pc.getPointcutExpression().getPointcutExpression();
assertThat(expr).isEqualTo("execution(* *(..)) && args(String) && this(Object)"); assertThat(expr).isEqualTo("execution(* *(..)) && args(String) && this(Object)");
@ -302,7 +302,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testMatchGenericArgument() { void testMatchGenericArgument() {
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )"; String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )";
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression); ajexp.setExpression(expression);
@ -321,7 +321,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testMatchVarargs() throws Exception { void testMatchVarargs() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
class MyTemplate { class MyTemplate {
@ -347,19 +347,19 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testMatchAnnotationOnClassWithAtWithin() throws Exception { void testMatchAnnotationOnClassWithAtWithin() throws Exception {
String expression = "@within(test.annotation.transaction.Tx)"; String expression = "@within(test.annotation.transaction.Tx)";
testMatchAnnotationOnClass(expression); testMatchAnnotationOnClass(expression);
} }
@Test @Test
public void testMatchAnnotationOnClassWithoutBinding() throws Exception { void testMatchAnnotationOnClassWithoutBinding() throws Exception {
String expression = "within(@test.annotation.transaction.Tx *)"; String expression = "within(@test.annotation.transaction.Tx *)";
testMatchAnnotationOnClass(expression); testMatchAnnotationOnClass(expression);
} }
@Test @Test
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception { void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception {
String expression = "within(@(test.annotation..*) *)"; String expression = "within(@(test.annotation..*) *)";
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression); AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse(); assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse();
@ -371,7 +371,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception { void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception {
String expression = "within(@(test.annotation.transaction.*) *)"; String expression = "within(@(test.annotation.transaction.*) *)";
testMatchAnnotationOnClass(expression); testMatchAnnotationOnClass(expression);
} }
@ -389,7 +389,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAnnotationOnMethodWithFQN() throws Exception { void testAnnotationOnMethodWithFQN() throws Exception {
String expression = "@annotation(test.annotation.transaction.Tx)"; String expression = "@annotation(test.annotation.transaction.Tx)";
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression); ajexp.setExpression(expression);
@ -403,7 +403,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAnnotationOnCglibProxyMethod() throws Exception { void testAnnotationOnCglibProxyMethod() throws Exception {
String expression = "@annotation(test.annotation.transaction.Tx)"; String expression = "@annotation(test.annotation.transaction.Tx)";
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression); ajexp.setExpression(expression);
@ -416,7 +416,7 @@ public class AspectJExpressionPointcutTests {
@Test @Test
public void testNotAnnotationOnCglibProxyMethod() throws Exception { void testNotAnnotationOnCglibProxyMethod() throws Exception {
String expression = "!@annotation(test.annotation.transaction.Tx)"; String expression = "!@annotation(test.annotation.transaction.Tx)";
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression); ajexp.setExpression(expression);
@ -428,7 +428,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAnnotationOnDynamicProxyMethod() throws Exception { void testAnnotationOnDynamicProxyMethod() throws Exception {
String expression = "@annotation(test.annotation.transaction.Tx)"; String expression = "@annotation(test.annotation.transaction.Tx)";
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression); ajexp.setExpression(expression);
@ -440,7 +440,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testNotAnnotationOnDynamicProxyMethod() throws Exception { void testNotAnnotationOnDynamicProxyMethod() throws Exception {
String expression = "!@annotation(test.annotation.transaction.Tx)"; String expression = "!@annotation(test.annotation.transaction.Tx)";
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression); ajexp.setExpression(expression);
@ -452,7 +452,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAnnotationOnMethodWithWildcard() throws Exception { void testAnnotationOnMethodWithWildcard() throws Exception {
String expression = "execution(@(test.annotation..*) * *(..))"; String expression = "execution(@(test.annotation..*) * *(..))";
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut(); AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
anySpringMethodAnnotation.setExpression(expression); anySpringMethodAnnotation.setExpression(expression);
@ -468,7 +468,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception { void testAnnotationOnMethodArgumentsWithFQN() throws Exception {
String expression = "@args(*, test.annotation.EmptySpringAnnotation))"; String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
takesSpringAnnotatedArgument2.setExpression(expression); takesSpringAnnotatedArgument2.setExpression(expression);
@ -497,7 +497,7 @@ public class AspectJExpressionPointcutTests {
} }
@Test @Test
public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception { void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
String expression = "execution(* *(*, @(test..*) *))"; String expression = "execution(* *(*, @(test..*) *))";
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
takesSpringAnnotatedArgument2.setExpression(expression); takesSpringAnnotatedArgument2.setExpression(expression);

9
spring-aop/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutMatchingTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Ramnivas Laddad * @author Ramnivas Laddad
* @author Chris Beams * @author Chris Beams
*/ */
public class BeanNamePointcutMatchingTests { class BeanNamePointcutMatchingTests {
@Test @Test
public void testMatchingPointcuts() { void testMatchingPointcuts() {
assertMatch("someName", "bean(someName)"); assertMatch("someName", "bean(someName)");
// Spring bean names are less restrictive compared to AspectJ names (methods, types etc.) // Spring bean names are less restrictive compared to AspectJ names (methods, types etc.)
@ -66,7 +66,7 @@ public class BeanNamePointcutMatchingTests {
} }
@Test @Test
public void testNonMatchingPointcuts() { void testNonMatchingPointcuts() {
assertMisMatch("someName", "bean(someNamex)"); assertMisMatch("someName", "bean(someNamex)");
assertMisMatch("someName", "bean(someX*Name)"); assertMisMatch("someName", "bean(someX*Name)");
@ -87,7 +87,6 @@ public class BeanNamePointcutMatchingTests {
} }
private static boolean matches(final String beanName, String pcExpression) { private static boolean matches(final String beanName, String pcExpression) {
@SuppressWarnings("serial")
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut() { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut() {
@Override @Override
protected String getCurrentProxiedBeanName() { protected String getCurrentProxiedBeanName() {

16
spring-aop/src/test/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPointTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,20 +46,20 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Ramnivas Laddad * @author Ramnivas Laddad
* @since 2.0 * @since 2.0
*/ */
public class MethodInvocationProceedingJoinPointTests { class MethodInvocationProceedingJoinPointTests {
@Test @Test
public void testingBindingWithJoinPoint() { void testingBindingWithJoinPoint() {
assertThatIllegalStateException().isThrownBy(AbstractAspectJAdvice::currentJoinPoint); assertThatIllegalStateException().isThrownBy(AbstractAspectJAdvice::currentJoinPoint);
} }
@Test @Test
public void testingBindingWithProceedingJoinPoint() { void testingBindingWithProceedingJoinPoint() {
assertThatIllegalStateException().isThrownBy(AbstractAspectJAdvice::currentJoinPoint); assertThatIllegalStateException().isThrownBy(AbstractAspectJAdvice::currentJoinPoint);
} }
@Test @Test
public void testCanGetMethodSignatureFromJoinPoint() { void testCanGetMethodSignatureFromJoinPoint() {
final Object raw = new TestBean(); final Object raw = new TestBean();
// Will be set by advice during a method call // Will be set by advice during a method call
final int newAge = 23; final int newAge = 23;
@ -118,7 +118,7 @@ public class MethodInvocationProceedingJoinPointTests {
} }
@Test @Test
public void testCanGetSourceLocationFromJoinPoint() { void testCanGetSourceLocationFromJoinPoint() {
final Object raw = new TestBean(); final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw); ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR); pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
@ -135,7 +135,7 @@ public class MethodInvocationProceedingJoinPointTests {
} }
@Test @Test
public void testCanGetStaticPartFromJoinPoint() { void testCanGetStaticPartFromJoinPoint() {
final Object raw = new TestBean(); final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw); ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR); pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
@ -152,7 +152,7 @@ public class MethodInvocationProceedingJoinPointTests {
} }
@Test @Test
public void toShortAndLongStringFormedCorrectly() throws Exception { void toShortAndLongStringFormedCorrectly() {
final Object raw = new TestBean(); final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw); ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR); pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);

25
spring-aop/src/test/java/org/springframework/aop/aspectj/TrickyAspectJPointcutExpressionTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,17 +40,17 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/** /**
* @author Dave Syer * @author Dave Syer
*/ */
public class TrickyAspectJPointcutExpressionTests { class TrickyAspectJPointcutExpressionTests {
@Test @Test
public void testManualProxyJavaWithUnconditionalPointcut() throws Exception { void testManualProxyJavaWithUnconditionalPointcut() {
TestService target = new TestServiceImpl(); TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice(); LogUserAdvice logAdvice = new LogUserAdvice();
testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "TestServiceImpl"); testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "TestServiceImpl");
} }
@Test @Test
public void testManualProxyJavaWithStaticPointcut() throws Exception { void testManualProxyJavaWithStaticPointcut() {
TestService target = new TestServiceImpl(); TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice(); LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
@ -59,7 +59,7 @@ public class TrickyAspectJPointcutExpressionTests {
} }
@Test @Test
public void testManualProxyJavaWithDynamicPointcut() throws Exception { void testManualProxyJavaWithDynamicPointcut() {
TestService target = new TestServiceImpl(); TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice(); LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
@ -68,7 +68,7 @@ public class TrickyAspectJPointcutExpressionTests {
} }
@Test @Test
public void testManualProxyJavaWithDynamicPointcutAndProxyTargetClass() throws Exception { void testManualProxyJavaWithDynamicPointcutAndProxyTargetClass() {
TestService target = new TestServiceImpl(); TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice(); LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
@ -77,7 +77,7 @@ public class TrickyAspectJPointcutExpressionTests {
} }
@Test @Test
public void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception { void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice(); LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
@ -95,13 +95,12 @@ public class TrickyAspectJPointcutExpressionTests {
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl"); testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");
} }
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message) private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message) {
throws Exception {
testAdvice(advisor, logAdvice, target, message, false); testAdvice(advisor, logAdvice, target, message, false);
} }
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message,
boolean proxyTargetClass) throws Exception { boolean proxyTargetClass) {
logAdvice.reset(); logAdvice.reset();
@ -148,7 +147,7 @@ public class TrickyAspectJPointcutExpressionTests {
public interface TestService { public interface TestService {
public String sayHello(); String sayHello();
} }
@ -162,14 +161,14 @@ public class TrickyAspectJPointcutExpressionTests {
} }
public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice { public static class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
private int countBefore = 0; private int countBefore = 0;
private int countThrows = 0; private int countThrows = 0;
@Override @Override
public void before(Method method, Object[] objects, @Nullable Object o) throws Throwable { public void before(Method method, Object[] objects, @Nullable Object o) {
countBefore++; countBefore++;
} }

2
spring-aop/src/test/java/org/springframework/aop/aspectj/TypePatternClassFilterTests.java

@ -51,7 +51,7 @@ class TypePatternClassFilterTests {
} }
@Test @Test
void invocationOfMatchesMethodBlowsUpWhenNoTypePatternHasBeenSet() throws Exception { void invocationOfMatchesMethodBlowsUpWhenNoTypePatternHasBeenSet() {
assertThatIllegalStateException().isThrownBy(() -> new TypePatternClassFilter().matches(String.class)); assertThatIllegalStateException().isThrownBy(() -> new TypePatternClassFilter().matches(String.class));
} }

12
spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -362,7 +362,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
assertThat(lockable.locked()).as("Already locked").isTrue(); assertThat(lockable.locked()).as("Already locked").isTrue();
lockable.lock(); lockable.lock();
assertThat(lockable.locked()).as("Real target ignores locking").isTrue(); assertThat(lockable.locked()).as("Real target ignores locking").isTrue();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> lockable.unlock()); assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(lockable::unlock);
} }
@Test @Test
@ -645,7 +645,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
static class NamedPointcutAspectWithFQN { static class NamedPointcutAspectWithFQN {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); private final ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
@Around("org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.CommonPointcuts.getAge()()") @Around("org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.CommonPointcuts.getAge()()")
int changeReturnValue(ProceedingJoinPoint pjp) { int changeReturnValue(ProceedingJoinPoint pjp) {
@ -762,7 +762,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
@Aspect @Aspect
class DoublingAspect { static class DoublingAspect {
@Around("execution(* getAge())") @Around("execution(* getAge())")
public Object doubleAge(ProceedingJoinPoint pjp) throws Throwable { public Object doubleAge(ProceedingJoinPoint pjp) throws Throwable {
@ -771,7 +771,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
} }
@Aspect @Aspect
class IncrementingAspect extends DoublingAspect { static class IncrementingAspect extends DoublingAspect {
@Around("execution(* getAge())") @Around("execution(* getAge())")
public int incrementAge(ProceedingJoinPoint pjp) throws Throwable { public int incrementAge(ProceedingJoinPoint pjp) throws Throwable {
@ -1080,7 +1080,7 @@ class PerThisAspect {
// Just to check that this doesn't cause problems with introduction processing // Just to check that this doesn't cause problems with introduction processing
@SuppressWarnings("unused") @SuppressWarnings("unused")
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); private final ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
@Around("execution(int *.getAge())") @Around("execution(int *.getAge())")
int returnCountAsAge() { int returnCountAsAge() {

6
spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java

@ -119,7 +119,7 @@ class ArgumentBindingTests {
static class PointcutWithAnnotationArgument { static class PointcutWithAnnotationArgument {
@Around("execution(* org.springframework..*.*(..)) && @annotation(transactional)") @Around("execution(* org.springframework..*.*(..)) && @annotation(transactional)")
public Object around(ProceedingJoinPoint pjp, Transactional transactional) throws Throwable { public Object around(ProceedingJoinPoint pjp, Transactional transactional) {
throw new IllegalStateException("Invoked with @Transactional"); throw new IllegalStateException("Invoked with @Transactional");
} }
} }
@ -132,7 +132,7 @@ class ArgumentBindingTests {
public void pointcutWithArgs(String s) {} public void pointcutWithArgs(String s) {}
@Around("pointcutWithArgs(aString)") @Around("pointcutWithArgs(aString)")
public Object doAround(ProceedingJoinPoint pjp, String aString) throws Throwable { public Object doAround(ProceedingJoinPoint pjp, String aString) {
throw new IllegalArgumentException(aString); throw new IllegalArgumentException(aString);
} }
} }
@ -142,7 +142,7 @@ class ArgumentBindingTests {
static class DynamicPointcutWithArgs { static class DynamicPointcutWithArgs {
@Around("execution(* *(..)) && args(java.lang.String)") @Around("execution(* *(..)) && args(java.lang.String)")
public Object doAround(ProceedingJoinPoint pjp) throws Throwable { public Object doAround(ProceedingJoinPoint pjp) {
throw new IllegalArgumentException(String.valueOf(pjp.getArgs()[0])); throw new IllegalArgumentException(String.valueOf(pjp.getArgs()[0]));
} }
} }

18
spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,9 +20,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.Pointcut; import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcut; import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionThrowingAspect; import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionThrowingAspect;
import org.springframework.aop.framework.AopConfigException; import org.springframework.aop.framework.AopConfigException;
import org.springframework.aop.testfixture.aspectj.CommonExpressions;
import org.springframework.aop.testfixture.aspectj.PerTargetAspect; import org.springframework.aop.testfixture.aspectj.PerTargetAspect;
import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.beans.testfixture.beans.TestBean;
@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class AspectJPointcutAdvisorTests { class AspectJPointcutAdvisorTests {
private final AspectJAdvisorFactory af = new ReflectiveAspectJAdvisorFactory(); private final AspectJAdvisorFactory af = new ReflectiveAspectJAdvisorFactory();
@Test @Test
public void testSingleton() throws SecurityException, NoSuchMethodException { void testSingleton() throws SecurityException, NoSuchMethodException {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); ajexp.setExpression(CommonExpressions.MATCH_ALL_METHODS);
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl( InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
ajexp, TestBean.class.getMethod("getAge"), af, ajexp, TestBean.class.getMethod("getAge"), af,
@ -53,9 +53,9 @@ public class AspectJPointcutAdvisorTests {
} }
@Test @Test
public void testPerTarget() throws SecurityException, NoSuchMethodException { void testPerTarget() throws SecurityException, NoSuchMethodException {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); ajexp.setExpression(CommonExpressions.MATCH_ALL_METHODS);
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl( InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
ajexp, TestBean.class.getMethod("getAge"), af, ajexp, TestBean.class.getMethod("getAge"), af,
@ -76,13 +76,13 @@ public class AspectJPointcutAdvisorTests {
} }
@Test @Test
public void testPerCflowTarget() { void testPerCflowTarget() {
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() -> assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowAspect.class)); testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowAspect.class));
} }
@Test @Test
public void testPerCflowBelowTarget() { void testPerCflowBelowTarget() {
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() -> assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowBelowAspect.class)); testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowBelowAspect.class));
} }

29
spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,17 +36,17 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class AspectProxyFactoryTests { class AspectProxyFactoryTests {
@Test @Test
public void testWithNonAspect() { void testWithNonAspect() {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
proxyFactory.addAspect(TestBean.class)); proxyFactory.addAspect(TestBean.class));
} }
@Test @Test
public void testWithSimpleAspect() throws Exception { void testWithSimpleAspect() {
TestBean bean = new TestBean(); TestBean bean = new TestBean();
bean.setAge(2); bean.setAge(2);
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(bean); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(bean);
@ -56,7 +56,7 @@ public class AspectProxyFactoryTests {
} }
@Test @Test
public void testWithPerThisAspect() throws Exception { void testWithPerThisAspect() {
TestBean bean1 = new TestBean(); TestBean bean1 = new TestBean();
TestBean bean2 = new TestBean(); TestBean bean2 = new TestBean();
@ -76,15 +76,14 @@ public class AspectProxyFactoryTests {
} }
@Test @Test
public void testWithInstanceWithNonAspect() throws Exception { void testWithInstanceWithNonAspect() {
AspectJProxyFactory pf = new AspectJProxyFactory(); AspectJProxyFactory pf = new AspectJProxyFactory();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
pf.addAspect(new TestBean())); pf.addAspect(new TestBean()));
} }
@Test @Test
@SuppressWarnings("unchecked") void testSerializable() throws Exception {
public void testSerializable() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnVarargs.class); proxyFactory.addAspect(LoggingAspectOnVarargs.class);
ITestBean proxy = proxyFactory.getProxy(); ITestBean proxy = proxyFactory.getProxy();
@ -94,7 +93,7 @@ public class AspectProxyFactoryTests {
} }
@Test @Test
public void testWithInstance() throws Exception { void testWithInstance() throws Exception {
MultiplyReturnValue aspect = new MultiplyReturnValue(); MultiplyReturnValue aspect = new MultiplyReturnValue();
int multiple = 3; int multiple = 3;
aspect.setMultiple(multiple); aspect.setMultiple(multiple);
@ -113,14 +112,13 @@ public class AspectProxyFactoryTests {
} }
@Test @Test
public void testWithNonSingletonAspectInstance() throws Exception { void testWithNonSingletonAspectInstance() {
AspectJProxyFactory pf = new AspectJProxyFactory(); AspectJProxyFactory pf = new AspectJProxyFactory();
assertThatIllegalArgumentException().isThrownBy(() -> pf.addAspect(new PerThisAspect())); assertThatIllegalArgumentException().isThrownBy(() -> pf.addAspect(new PerThisAspect()));
} }
@Test // SPR-13328 @Test // SPR-13328
@SuppressWarnings("unchecked") public void testProxiedVarargsWithEnumArray() {
public void testProxiedVarargsWithEnumArray() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnVarargs.class); proxyFactory.addAspect(LoggingAspectOnVarargs.class);
ITestBean proxy = proxyFactory.getProxy(); ITestBean proxy = proxyFactory.getProxy();
@ -128,8 +126,7 @@ public class AspectProxyFactoryTests {
} }
@Test // SPR-13328 @Test // SPR-13328
@SuppressWarnings("unchecked") public void testUnproxiedVarargsWithEnumArray() {
public void testUnproxiedVarargsWithEnumArray() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnSetter.class); proxyFactory.addAspect(LoggingAspectOnSetter.class);
ITestBean proxy = proxyFactory.getProxy(); ITestBean proxy = proxyFactory.getProxy();
@ -174,13 +171,13 @@ public class AspectProxyFactoryTests {
public enum MyEnum implements MyInterface { public enum MyEnum implements MyInterface {
A, B; A, B
} }
public enum MyOtherEnum implements MyInterface { public enum MyOtherEnum implements MyInterface {
C, D; C, D
} }

14
spring-aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Rob Harrop * @author Rob Harrop
* @author Chris Beams * @author Chris Beams
*/ */
public class AspectJNamespaceHandlerTests { class AspectJNamespaceHandlerTests {
private ParserContext parserContext; private ParserContext parserContext;
@ -47,7 +47,7 @@ public class AspectJNamespaceHandlerTests {
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setUp() {
SourceExtractor sourceExtractor = new PassThroughSourceExtractor(); SourceExtractor sourceExtractor = new PassThroughSourceExtractor();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry);
XmlReaderContext readerContext = XmlReaderContext readerContext =
@ -56,7 +56,7 @@ public class AspectJNamespaceHandlerTests {
} }
@Test @Test
public void testRegisterAutoProxyCreator() throws Exception { void testRegisterAutoProxyCreator() {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1); assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
@ -65,7 +65,7 @@ public class AspectJNamespaceHandlerTests {
} }
@Test @Test
public void testRegisterAspectJAutoProxyCreator() throws Exception { void testRegisterAspectJAutoProxyCreator() {
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1); assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
@ -77,7 +77,7 @@ public class AspectJNamespaceHandlerTests {
} }
@Test @Test
public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception { void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
assertThat(registry.getBeanDefinitionCount()).isEqualTo(1); assertThat(registry.getBeanDefinitionCount()).isEqualTo(1);
@ -89,7 +89,7 @@ public class AspectJNamespaceHandlerTests {
} }
@Test @Test
public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception { void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() {
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertThat(registry.getBeanDefinitionCount()).isEqualTo(1); assertThat(registry.getBeanDefinitionCount()).isEqualTo(1);

24
spring-aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparatorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Adrian Colyer * @author Adrian Colyer
* @author Chris Beams * @author Chris Beams
*/ */
public class AspectJPrecedenceComparatorTests { class AspectJPrecedenceComparatorTests {
private static final int HIGH_PRECEDENCE_ADVISOR_ORDER = 100; private static final int HIGH_PRECEDENCE_ADVISOR_ORDER = 100;
private static final int LOW_PRECEDENCE_ADVISOR_ORDER = 200; private static final int LOW_PRECEDENCE_ADVISOR_ORDER = 200;
@ -56,7 +56,7 @@ public class AspectJPrecedenceComparatorTests {
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setUp() {
this.comparator = new AspectJPrecedenceComparator(); this.comparator = new AspectJPrecedenceComparator();
this.anyOldMethod = getClass().getMethods()[0]; this.anyOldMethod = getClass().getMethods()[0];
this.anyOldPointcut = new AspectJExpressionPointcut(); this.anyOldPointcut = new AspectJExpressionPointcut();
@ -65,7 +65,7 @@ public class AspectJPrecedenceComparatorTests {
@Test @Test
public void testSameAspectNoAfterAdvice() { void testSameAspectNoAfterAdvice() {
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
@ -76,7 +76,7 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testSameAspectAfterAdvice() { void testSameAspectAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before advisor1").isEqualTo(1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before advisor1").isEqualTo(1);
@ -87,14 +87,14 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testSameAspectOneOfEach() { void testSameAspectOneOfEach() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 and advisor2 not comparable").isEqualTo(1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 and advisor2 not comparable").isEqualTo(1);
} }
@Test @Test
public void testSameAdvisorPrecedenceDifferentAspectNoAfterAdvice() { void testSameAdvisorPrecedenceDifferentAspectNoAfterAdvice() {
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0); assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
@ -105,7 +105,7 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testSameAdvisorPrecedenceDifferentAspectAfterAdvice() { void testSameAdvisorPrecedenceDifferentAspectAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0); assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
@ -116,7 +116,7 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testHigherAdvisorPrecedenceNoAfterAdvice() { void testHigherAdvisorPrecedenceNoAfterAdvice() {
Advisor advisor1 = createSpringAOPBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER); Advisor advisor1 = createSpringAOPBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER);
Advisor advisor2 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); Advisor advisor2 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
@ -127,7 +127,7 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testHigherAdvisorPrecedenceAfterAdvice() { void testHigherAdvisorPrecedenceAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); Advisor advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
@ -138,7 +138,7 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testLowerAdvisorPrecedenceNoAfterAdvice() { void testLowerAdvisorPrecedenceNoAfterAdvice() {
Advisor advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
@ -149,7 +149,7 @@ public class AspectJPrecedenceComparatorTests {
} }
@Test @Test
public void testLowerAdvisorPrecedenceAfterAdvice() { void testLowerAdvisorPrecedenceAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); Advisor advisor1 = createAspectJAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1); assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);

8
spring-aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,14 +25,14 @@ import org.springframework.util.StopWatch;
/** /**
* Benchmarks for introductions. * Benchmarks for introductions.
* * <p>
* NOTE: No assertions! * NOTE: No assertions!
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
* @since 2.0 * @since 2.0
*/ */
public class IntroductionBenchmarkTests { class IntroductionBenchmarkTests {
private static final int EXPECTED_COMPARE = 13; private static final int EXPECTED_COMPARE = 13;
@ -53,7 +53,7 @@ public class IntroductionBenchmarkTests {
} }
@Test @Test
public void timeManyInvocations() { void timeManyInvocations() {
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
TestBean target = new TestBean(); TestBean target = new TestBean();

14
spring-aop/src/test/java/org/springframework/aop/framework/NullPrimitiveTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,14 +29,14 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class NullPrimitiveTests { class NullPrimitiveTests {
interface Foo { interface Foo {
int getValue(); int getValue();
} }
@Test @Test
public void testNullPrimitiveWithJdkProxy() { void testNullPrimitiveWithJdkProxy() {
class SimpleFoo implements Foo { class SimpleFoo implements Foo {
@Override @Override
@ -51,8 +51,7 @@ public class NullPrimitiveTests {
Foo foo = (Foo) factory.getProxy(); Foo foo = (Foo) factory.getProxy();
assertThatExceptionOfType(AopInvocationException.class).isThrownBy(() -> assertThatExceptionOfType(AopInvocationException.class).isThrownBy(foo::getValue)
foo.getValue())
.withMessageContaining("Foo.getValue()"); .withMessageContaining("Foo.getValue()");
} }
@ -63,7 +62,7 @@ public class NullPrimitiveTests {
} }
@Test @Test
public void testNullPrimitiveWithCglibProxy() { void testNullPrimitiveWithCglibProxy() {
Bar target = new Bar(); Bar target = new Bar();
ProxyFactory factory = new ProxyFactory(target); ProxyFactory factory = new ProxyFactory(target);
@ -71,8 +70,7 @@ public class NullPrimitiveTests {
Bar bar = (Bar) factory.getProxy(); Bar bar = (Bar) factory.getProxy();
assertThatExceptionOfType(AopInvocationException.class).isThrownBy(() -> assertThatExceptionOfType(AopInvocationException.class).isThrownBy(bar::getValue)
bar.getValue())
.withMessageContaining("Bar.getValue()"); .withMessageContaining("Bar.getValue()");
} }

8
spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,13 +32,13 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Chris Beams * @author Chris Beams
* @since 03.09.2004 * @since 03.09.2004
*/ */
public class PrototypeTargetTests { class PrototypeTargetTests {
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml"); private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml");
@Test @Test
public void testPrototypeProxyWithPrototypeTarget() { void testPrototypeProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0; TestBeanImpl.constructionCount = 0;
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
@ -52,7 +52,7 @@ public class PrototypeTargetTests {
} }
@Test @Test
public void testSingletonProxyWithPrototypeTarget() { void testSingletonProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0; TestBeanImpl.constructionCount = 0;
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);

46
spring-aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,10 +57,10 @@ import static org.assertj.core.api.Assertions.assertThatRuntimeException;
* @author Chris Beams * @author Chris Beams
* @since 14.05.2003 * @since 14.05.2003
*/ */
public class ProxyFactoryTests { class ProxyFactoryTests {
@Test @Test
public void testIndexOfMethods() { void testIndexOfMethods() {
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor(); NopInterceptor nop = new NopInterceptor();
@ -76,7 +76,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testRemoveAdvisorByReference() { void testRemoveAdvisorByReference() {
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor(); NopInterceptor nop = new NopInterceptor();
@ -96,7 +96,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testRemoveAdvisorByIndex() { void testRemoveAdvisorByIndex() {
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor(); NopInterceptor nop = new NopInterceptor();
@ -144,7 +144,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testReplaceAdvisor() { void testReplaceAdvisor() {
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor(); NopInterceptor nop = new NopInterceptor();
@ -173,7 +173,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testAddRepeatedInterface() { void testAddRepeatedInterface() {
TimeStamped tst = () -> { TimeStamped tst = () -> {
throw new UnsupportedOperationException("getTimeStamp"); throw new UnsupportedOperationException("getTimeStamp");
}; };
@ -186,7 +186,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testGetsAllInterfaces() { void testGetsAllInterfaces() {
// Extend to get new interface // Extend to get new interface
class TestBeanSubclass extends TestBean implements Comparable<Object> { class TestBeanSubclass extends TestBean implements Comparable<Object> {
@Override @Override
@ -220,10 +220,10 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testInterceptorInclusionMethods() { void testInterceptorInclusionMethods() {
class MyInterceptor implements MethodInterceptor { class MyInterceptor implements MethodInterceptor {
@Override @Override
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
@ -244,9 +244,9 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testSealedInterfaceExclusion() { void testSealedInterfaceExclusion() {
// String implements ConstantDesc on JDK 12+, sealed as of JDK 17 // String implements ConstantDesc on JDK 12+, sealed as of JDK 17
ProxyFactory factory = new ProxyFactory(new String()); ProxyFactory factory = new ProxyFactory("");
NopInterceptor di = new NopInterceptor(); NopInterceptor di = new NopInterceptor();
factory.addAdvice(0, di); factory.addAdvice(0, di);
Object proxy = factory.getProxy(); Object proxy = factory.getProxy();
@ -257,7 +257,7 @@ public class ProxyFactoryTests {
* Should see effect immediately on behavior. * Should see effect immediately on behavior.
*/ */
@Test @Test
public void testCanAddAndRemoveAspectInterfacesOnSingleton() { void testCanAddAndRemoveAspectInterfacesOnSingleton() {
ProxyFactory config = new ProxyFactory(new TestBean()); ProxyFactory config = new ProxyFactory(new TestBean());
assertThat(config.getProxy()).as("Shouldn't implement TimeStamped before manipulation") assertThat(config.getProxy()).as("Shouldn't implement TimeStamped before manipulation")
@ -304,7 +304,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testProxyTargetClassWithInterfaceAsTarget() { void testProxyTargetClassWithInterfaceAsTarget() {
ProxyFactory pf = new ProxyFactory(); ProxyFactory pf = new ProxyFactory();
pf.setTargetClass(ITestBean.class); pf.setTargetClass(ITestBean.class);
Object proxy = pf.getProxy(); Object proxy = pf.getProxy();
@ -320,7 +320,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testProxyTargetClassWithConcreteClassAsTarget() { void testProxyTargetClassWithConcreteClassAsTarget() {
ProxyFactory pf = new ProxyFactory(); ProxyFactory pf = new ProxyFactory();
pf.setTargetClass(TestBean.class); pf.setTargetClass(TestBean.class);
Object proxy = pf.getProxy(); Object proxy = pf.getProxy();
@ -347,7 +347,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testInterfaceProxiesCanBeOrderedThroughAnnotations() { void testInterfaceProxiesCanBeOrderedThroughAnnotations() {
Object proxy1 = new ProxyFactory(new A()).getProxy(); Object proxy1 = new ProxyFactory(new A()).getProxy();
Object proxy2 = new ProxyFactory(new B()).getProxy(); Object proxy2 = new ProxyFactory(new B()).getProxy();
List<Object> list = new ArrayList<>(2); List<Object> list = new ArrayList<>(2);
@ -359,7 +359,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testTargetClassProxiesCanBeOrderedThroughAnnotations() { void testTargetClassProxiesCanBeOrderedThroughAnnotations() {
ProxyFactory pf1 = new ProxyFactory(new A()); ProxyFactory pf1 = new ProxyFactory(new A());
pf1.setProxyTargetClass(true); pf1.setProxyTargetClass(true);
ProxyFactory pf2 = new ProxyFactory(new B()); ProxyFactory pf2 = new ProxyFactory(new B());
@ -375,7 +375,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testInterceptorWithoutJoinpoint() { void testInterceptorWithoutJoinpoint() {
final TestBean target = new TestBean("tb"); final TestBean target = new TestBean("tb");
ITestBean proxy = ProxyFactory.getProxy(ITestBean.class, (MethodInterceptor) invocation -> { ITestBean proxy = ProxyFactory.getProxy(ITestBean.class, (MethodInterceptor) invocation -> {
assertThat(invocation.getThis()).isNull(); assertThat(invocation.getThis()).isNull();
@ -385,7 +385,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testCharSequenceProxy() { void testCharSequenceProxy() {
CharSequence target = "test"; CharSequence target = "test";
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
ClassLoader cl = target.getClass().getClassLoader(); ClassLoader cl = target.getClass().getClassLoader();
@ -395,7 +395,7 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testDateProxy() { void testDateProxy() {
Date target = new Date(); Date target = new Date();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
pf.setProxyTargetClass(true); pf.setProxyTargetClass(true);
@ -406,14 +406,14 @@ public class ProxyFactoryTests {
} }
@Test @Test
public void testJdbcSavepointProxy() throws SQLException { void testJdbcSavepointProxy() throws SQLException {
Savepoint target = new Savepoint() { Savepoint target = new Savepoint() {
@Override @Override
public int getSavepointId() throws SQLException { public int getSavepointId() {
return 1; return 1;
} }
@Override @Override
public String getSavepointName() throws SQLException { public String getSavepointName() {
return "sp"; return "sp";
} }
}; };

17
spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,17 +37,17 @@ import static org.mockito.Mockito.mock;
* @author Chris Beams * @author Chris Beams
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class ThrowsAdviceInterceptorTests { class ThrowsAdviceInterceptorTests {
@Test @Test
public void testNoHandlerMethods() { void testNoHandlerMethods() {
// should require one handler method at least // should require one handler method at least
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() -> assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
new ThrowsAdviceInterceptor(new Object())); new ThrowsAdviceInterceptor(new Object()));
} }
@Test @Test
public void testNotInvoked() throws Throwable { void testNotInvoked() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler(); MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th); ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
Object ret = new Object(); Object ret = new Object();
@ -58,7 +58,7 @@ public class ThrowsAdviceInterceptorTests {
} }
@Test @Test
public void testNoHandlerMethodForThrowable() throws Throwable { void testNoHandlerMethodForThrowable() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler(); MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th); ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
assertThat(ti.getHandlerMethodCount()).isEqualTo(2); assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
@ -70,7 +70,7 @@ public class ThrowsAdviceInterceptorTests {
} }
@Test @Test
public void testCorrectHandlerUsed() throws Throwable { void testCorrectHandlerUsed() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler(); MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th); ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
FileNotFoundException ex = new FileNotFoundException(); FileNotFoundException ex = new FileNotFoundException();
@ -84,7 +84,7 @@ public class ThrowsAdviceInterceptorTests {
} }
@Test @Test
public void testCorrectHandlerUsedForSubclass() throws Throwable { void testCorrectHandlerUsedForSubclass() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler(); MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th); ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
// Extends RemoteException // Extends RemoteException
@ -97,10 +97,9 @@ public class ThrowsAdviceInterceptorTests {
} }
@Test @Test
public void testHandlerMethodThrowsException() throws Throwable { void testHandlerMethodThrowsException() throws Throwable {
final Throwable t = new Throwable(); final Throwable t = new Throwable();
@SuppressWarnings("serial")
MyThrowsHandler th = new MyThrowsHandler() { MyThrowsHandler th = new MyThrowsHandler() {
@Override @Override
public void afterThrowing(RemoteException ex) throws Throwable { public void afterThrowing(RemoteException ex) throws Throwable {

14
spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.assertThat;
* @author Chris Beams * @author Chris Beams
* @since 06.04.2004 * @since 06.04.2004
*/ */
public class ConcurrencyThrottleInterceptorTests { class ConcurrencyThrottleInterceptorTests {
protected static final Log logger = LogFactory.getLog(ConcurrencyThrottleInterceptorTests.class); protected static final Log logger = LogFactory.getLog(ConcurrencyThrottleInterceptorTests.class);
@ -44,7 +44,7 @@ public class ConcurrencyThrottleInterceptorTests {
@Test @Test
public void testSerializable() throws Exception { void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean(); DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory(); ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean.class); proxyFactory.setInterfaces(ITestBean.class);
@ -63,12 +63,12 @@ public class ConcurrencyThrottleInterceptorTests {
} }
@Test @Test
public void testMultipleThreadsWithLimit1() { void testMultipleThreadsWithLimit1() {
testMultipleThreads(1); testMultipleThreads(1);
} }
@Test @Test
public void testMultipleThreadsWithLimit10() { void testMultipleThreadsWithLimit10() {
testMultipleThreads(10); testMultipleThreads(10);
} }
@ -111,8 +111,8 @@ public class ConcurrencyThrottleInterceptorTests {
private static class ConcurrencyThread extends Thread { private static class ConcurrencyThread extends Thread {
private ITestBean proxy; private final ITestBean proxy;
private Throwable ex; private final Throwable ex;
public ConcurrencyThread(ITestBean proxy, Throwable ex) { public ConcurrencyThread(ITestBean proxy, Throwable ex) {
this.proxy = proxy; this.proxy = proxy;

5
spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -144,7 +144,7 @@ class CustomizableTraceInterceptorTests {
void sunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable { void sunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
MethodInvocation methodInvocation = mock(); MethodInvocation methodInvocation = mock();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[0])); given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this); given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.getArguments()).willReturn(new Object[]{"$ One \\$", 2L}); given(methodInvocation.getArguments()).willReturn(new Object[]{"$ One \\$", 2L});
given(methodInvocation.proceed()).willReturn("Hello!"); given(methodInvocation.proceed()).willReturn("Hello!");
@ -177,7 +177,6 @@ class CustomizableTraceInterceptorTests {
* is properly configured in {@link CustomizableTraceInterceptor}. * is properly configured in {@link CustomizableTraceInterceptor}.
*/ */
@Test @Test
@SuppressWarnings("deprecation")
void supportedPlaceholderValues() { void supportedPlaceholderValues() {
assertThat(ALLOWED_PLACEHOLDERS).containsExactlyInAnyOrderElementsOf(getPlaceholderConstantValues()); assertThat(ALLOWED_PLACEHOLDERS).containsExactlyInAnyOrderElementsOf(getPlaceholderConstantValues());
} }

6
spring-aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java

@ -35,10 +35,10 @@ import static org.mockito.Mockito.verify;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
public class DebugInterceptorTests { class DebugInterceptorTests {
@Test @Test
public void testSunnyDayPathLogsCorrectly() throws Throwable { void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(); MethodInvocation methodInvocation = mock();
Log log = mock(); Log log = mock();
@ -52,7 +52,7 @@ public class DebugInterceptorTests {
} }
@Test @Test
public void testExceptionPathStillLogsCorrectly() throws Throwable { void testExceptionPathStillLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(); MethodInvocation methodInvocation = mock();
IllegalArgumentException exception = new IllegalArgumentException(); IllegalArgumentException exception = new IllegalArgumentException();

10
spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,9 +29,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ExposeBeanNameAdvisorsTests { class ExposeBeanNameAdvisorsTests {
private class RequiresBeanNameBoundTestBean extends TestBean { private static class RequiresBeanNameBoundTestBean extends TestBean {
private final String beanName; private final String beanName;
public RequiresBeanNameBoundTestBean(String beanName) { public RequiresBeanNameBoundTestBean(String beanName) {
@ -46,7 +46,7 @@ public class ExposeBeanNameAdvisorsTests {
} }
@Test @Test
public void testNoIntroduction() { void testNoIntroduction() {
String beanName = "foo"; String beanName = "foo";
TestBean target = new RequiresBeanNameBoundTestBean(beanName); TestBean target = new RequiresBeanNameBoundTestBean(beanName);
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
@ -61,7 +61,7 @@ public class ExposeBeanNameAdvisorsTests {
} }
@Test @Test
public void testWithIntroduction() { void testWithIntroduction() {
String beanName = "foo"; String beanName = "foo";
TestBean target = new RequiresBeanNameBoundTestBean(beanName); TestBean target = new RequiresBeanNameBoundTestBean(beanName);
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);

6
spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,10 +31,10 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ExposeInvocationInterceptorTests { class ExposeInvocationInterceptorTests {
@Test @Test
public void testXmlConfig() { void testXmlConfig() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml")); qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml"));

14
spring-aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@ import static org.mockito.Mockito.verify;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
public class PerformanceMonitorInterceptorTests { class PerformanceMonitorInterceptorTests {
@Test @Test
public void testSuffixAndPrefixAssignment() { void testSuffixAndPrefixAssignment() {
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(); PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor();
assertThat(interceptor.getPrefix()).isNotNull(); assertThat(interceptor.getPrefix()).isNotNull();
@ -49,9 +49,9 @@ public class PerformanceMonitorInterceptorTests {
} }
@Test @Test
public void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable { void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable {
MethodInvocation mi = mock(); MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0])); given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
Log log = mock(); Log log = mock();
@ -62,10 +62,10 @@ public class PerformanceMonitorInterceptorTests {
} }
@Test @Test
public void testExceptionPathStillLogsPerformanceMetricsCorrectly() throws Throwable { void testExceptionPathStillLogsPerformanceMetricsCorrectly() throws Throwable {
MethodInvocation mi = mock(); MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0])); given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.proceed()).willThrow(new IllegalArgumentException()); given(mi.proceed()).willThrow(new IllegalArgumentException());
Log log = mock(); Log log = mock();

6
spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java

@ -34,10 +34,10 @@ import static org.mockito.Mockito.verify;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
public class SimpleTraceInterceptorTests { class SimpleTraceInterceptorTests {
@Test @Test
public void testSunnyDayPathLogsCorrectly() throws Throwable { void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation mi = mock(); MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString")); given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.getThis()).willReturn(this); given(mi.getThis()).willReturn(this);
@ -51,7 +51,7 @@ public class SimpleTraceInterceptorTests {
} }
@Test @Test
public void testExceptionPathStillLogsCorrectly() throws Throwable { void testExceptionPathStillLogsCorrectly() throws Throwable {
MethodInvocation mi = mock(); MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString")); given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.getThis()).willReturn(this); given(mi.getThis()).willReturn(this);

10
spring-aop/src/test/java/org/springframework/aop/scope/DefaultScopedObjectTests.java

@ -29,31 +29,31 @@ import static org.mockito.Mockito.mock;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
public class DefaultScopedObjectTests { class DefaultScopedObjectTests {
private static final String GOOD_BEAN_NAME = "foo"; private static final String GOOD_BEAN_NAME = "foo";
@Test @Test
public void testCtorWithNullBeanFactory() throws Exception { void testCtorWithNullBeanFactory() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new DefaultScopedObject(null, GOOD_BEAN_NAME)); new DefaultScopedObject(null, GOOD_BEAN_NAME));
} }
@Test @Test
public void testCtorWithNullTargetBeanName() throws Exception { void testCtorWithNullTargetBeanName() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
testBadTargetBeanName(null)); testBadTargetBeanName(null));
} }
@Test @Test
public void testCtorWithEmptyTargetBeanName() throws Exception { void testCtorWithEmptyTargetBeanName() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
testBadTargetBeanName("")); testBadTargetBeanName(""));
} }
@Test @Test
public void testCtorWithJustWhitespacedTargetBeanName() throws Exception { void testCtorWithJustWhitespacedTargetBeanName() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
testBadTargetBeanName(" ")); testBadTargetBeanName(" "));
} }

8
spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,10 +31,10 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class ScopedProxyAutowireTests { class ScopedProxyAutowireTests {
@Test @Test
public void testScopedProxyInheritsAutowireCandidateFalse() { void testScopedProxyInheritsAutowireCandidateFalse() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml")); qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml"));
@ -48,7 +48,7 @@ public class ScopedProxyAutowireTests {
} }
@Test @Test
public void testScopedProxyReplacesAutowireCandidateTrue() { void testScopedProxyReplacesAutowireCandidateTrue() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml")); qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml"));

14
spring-aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class AopUtilsTests { class AopUtilsTests {
@Test @Test
public void testPointcutCanNeverApply() { void testPointcutCanNeverApply() {
class TestPointcut extends StaticMethodMatcherPointcut { class TestPointcut extends StaticMethodMatcherPointcut {
@Override @Override
public boolean matches(Method method, @Nullable Class<?> clazzy) { public boolean matches(Method method, @Nullable Class<?> clazzy) {
@ -54,13 +54,13 @@ public class AopUtilsTests {
} }
@Test @Test
public void testPointcutAlwaysApplies() { void testPointcutAlwaysApplies() {
assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class)).isTrue(); assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class)).isTrue();
assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class)).isTrue(); assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class)).isTrue();
} }
@Test @Test
public void testPointcutAppliesToOneMethodOnObject() { void testPointcutAppliesToOneMethodOnObject() {
class TestPointcut extends StaticMethodMatcherPointcut { class TestPointcut extends StaticMethodMatcherPointcut {
@Override @Override
public boolean matches(Method method, @Nullable Class<?> clazz) { public boolean matches(Method method, @Nullable Class<?> clazz) {
@ -80,7 +80,7 @@ public class AopUtilsTests {
* that's subverted the singleton construction limitation. * that's subverted the singleton construction limitation.
*/ */
@Test @Test
public void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception { void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception {
assertThat(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)).isSameAs(MethodMatcher.TRUE); assertThat(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)).isSameAs(MethodMatcher.TRUE);
assertThat(SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE)).isSameAs(ClassFilter.TRUE); assertThat(SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE)).isSameAs(ClassFilter.TRUE);
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE)).isSameAs(Pointcut.TRUE); assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE)).isSameAs(Pointcut.TRUE);
@ -91,7 +91,7 @@ public class AopUtilsTests {
} }
@Test @Test
public void testInvokeJoinpointUsingReflection() throws Throwable { void testInvokeJoinpointUsingReflection() throws Throwable {
String name = "foo"; String name = "foo";
TestBean testBean = new TestBean(name); TestBean testBean = new TestBean(name);
Method method = ReflectionUtils.findMethod(TestBean.class, "getName"); Method method = ReflectionUtils.findMethod(TestBean.class, "getName");

21
spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ComposablePointcutTests { class ComposablePointcutTests {
public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() { public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() {
@Override @Override
@ -56,23 +56,16 @@ public class ComposablePointcutTests {
} }
}; };
public static MethodMatcher SETTER_METHOD_MATCHER = new StaticMethodMatcher() {
@Override
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getName().startsWith("set");
}
};
@Test @Test
public void testMatchAll() throws NoSuchMethodException { void testMatchAll() throws NoSuchMethodException {
Pointcut pc = new ComposablePointcut(); Pointcut pc = new ComposablePointcut();
assertThat(pc.getClassFilter().matches(Object.class)).isTrue(); assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
assertThat(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class)).isTrue(); assertThat(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class)).isTrue();
} }
@Test @Test
public void testFilterByClass() throws NoSuchMethodException { void testFilterByClass() {
ComposablePointcut pc = new ComposablePointcut(); ComposablePointcut pc = new ComposablePointcut();
assertThat(pc.getClassFilter().matches(Object.class)).isTrue(); assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
@ -92,7 +85,7 @@ public class ComposablePointcutTests {
} }
@Test @Test
public void testUnionMethodMatcher() { void testUnionMethodMatcher() {
// Matches the getAge() method in any class // Matches the getAge() method in any class
ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER); ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER);
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse(); assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
@ -115,7 +108,7 @@ public class ComposablePointcutTests {
} }
@Test @Test
public void testIntersectionMethodMatcher() { void testIntersectionMethodMatcher() {
ComposablePointcut pc = new ComposablePointcut(); ComposablePointcut pc = new ComposablePointcut();
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue(); assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue(); assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
@ -132,7 +125,7 @@ public class ComposablePointcutTests {
} }
@Test @Test
public void testEqualsAndHashCode() throws Exception { void testEqualsAndHashCode() {
ComposablePointcut pc1 = new ComposablePointcut(); ComposablePointcut pc1 = new ComposablePointcut();
ComposablePointcut pc2 = new ComposablePointcut(); ComposablePointcut pc2 = new ComposablePointcut();

4
spring-aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -203,7 +203,7 @@ class ControlFlowPointcutTests {
// Will not be advised: not under MyComponent // Will not be advised: not under MyComponent
assertThat(proxy.getAge()).isEqualTo(target.getAge()); assertThat(proxy.getAge()).isEqualTo(target.getAge());
assertThat(cflow.getEvaluations()).isEqualTo(1 * evaluationFactor); assertThat(cflow.getEvaluations()).isEqualTo(evaluationFactor);
assertThat(nop.getCount()).isEqualTo(0); assertThat(nop.getCount()).isEqualTo(0);
// Will be advised: the proxy is invoked under MyComponent#getAge // Will be advised: the proxy is invoked under MyComponent#getAge

19
spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,14 +47,14 @@ import static org.mockito.Mockito.mock;
class DelegatingIntroductionInterceptorTests { class DelegatingIntroductionInterceptorTests {
@Test @Test
void testNullTarget() throws Exception { void testNullTarget() {
// Shouldn't accept null target // Shouldn't accept null target
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new DelegatingIntroductionInterceptor(null)); new DelegatingIntroductionInterceptor(null));
} }
@Test @Test
void testIntroductionInterceptorWithDelegation() throws Exception { void testIntroductionInterceptorWithDelegation() {
TestBean raw = new TestBean(); TestBean raw = new TestBean();
assertThat(raw).isNotInstanceOf(TimeStamped.class); assertThat(raw).isNotInstanceOf(TimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw); ProxyFactory factory = new ProxyFactory(raw);
@ -70,7 +70,7 @@ class DelegatingIntroductionInterceptorTests {
} }
@Test @Test
void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception { void testIntroductionInterceptorWithInterfaceHierarchy() {
TestBean raw = new TestBean(); TestBean raw = new TestBean();
assertThat(raw).isNotInstanceOf(SubTimeStamped.class); assertThat(raw).isNotInstanceOf(SubTimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw); ProxyFactory factory = new ProxyFactory(raw);
@ -86,7 +86,7 @@ class DelegatingIntroductionInterceptorTests {
} }
@Test @Test
void testIntroductionInterceptorWithSuperInterface() throws Exception { void testIntroductionInterceptorWithSuperInterface() {
TestBean raw = new TestBean(); TestBean raw = new TestBean();
assertThat(raw).isNotInstanceOf(TimeStamped.class); assertThat(raw).isNotInstanceOf(TimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw); ProxyFactory factory = new ProxyFactory(raw);
@ -107,7 +107,7 @@ class DelegatingIntroductionInterceptorTests {
final long t = 1001L; final long t = 1001L;
class Tester implements TimeStamped, ITester { class Tester implements TimeStamped, ITester {
@Override @Override
public void foo() throws Exception { public void foo() {
} }
@Override @Override
public long getTimeStamp() { public long getTimeStamp() {
@ -138,7 +138,7 @@ class DelegatingIntroductionInterceptorTests {
@SuppressWarnings("serial") @SuppressWarnings("serial")
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester { class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
@Override @Override
public void foo() throws Exception { public void foo() {
} }
@Override @Override
public long getTimeStamp() { public long getTimeStamp() {
@ -177,9 +177,8 @@ class DelegatingIntroductionInterceptorTests {
assertThat(o).isNotInstanceOf(TimeStamped.class); assertThat(o).isNotInstanceOf(TimeStamped.class);
} }
@SuppressWarnings("serial")
@Test @Test
void testIntroductionInterceptorDoesntReplaceToString() throws Exception { void testIntroductionInterceptorDoesNotReplaceToString() {
TestBean raw = new TestBean(); TestBean raw = new TestBean();
assertThat(raw).isNotInstanceOf(TimeStamped.class); assertThat(raw).isNotInstanceOf(TimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw); ProxyFactory factory = new ProxyFactory(raw);
@ -246,7 +245,7 @@ class DelegatingIntroductionInterceptorTests {
// Test when target implements the interface: should get interceptor by preference. // Test when target implements the interface: should get interceptor by preference.
@Test @Test
void testIntroductionMasksTargetImplementation() throws Exception { void testIntroductionMasksTargetImplementation() {
final long t = 1001L; final long t = 1001L;
@SuppressWarnings("serial") @SuppressWarnings("serial")
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped { class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {

16
spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class MethodMatchersTests { class MethodMatchersTests {
private static final Method TEST_METHOD = mock(Method.class); private static final Method TEST_METHOD = mock(Method.class);
@ -56,19 +56,19 @@ public class MethodMatchersTests {
@Test @Test
public void testDefaultMatchesAll() throws Exception { void testDefaultMatchesAll() {
MethodMatcher defaultMm = MethodMatcher.TRUE; MethodMatcher defaultMm = MethodMatcher.TRUE;
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue(); assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue(); assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
} }
@Test @Test
public void testMethodMatcherTrueSerializable() throws Exception { void testMethodMatcherTrueSerializable() throws Exception {
assertThat(MethodMatcher.TRUE).isSameAs(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)); assertThat(MethodMatcher.TRUE).isSameAs(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE));
} }
@Test @Test
public void testSingle() throws Exception { void testSingle() {
MethodMatcher defaultMm = MethodMatcher.TRUE; MethodMatcher defaultMm = MethodMatcher.TRUE;
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue(); assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue(); assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
@ -80,7 +80,7 @@ public class MethodMatchersTests {
@Test @Test
public void testDynamicAndStaticMethodMatcherIntersection() throws Exception { void testDynamicAndStaticMethodMatcherIntersection() {
MethodMatcher mm1 = MethodMatcher.TRUE; MethodMatcher mm1 = MethodMatcher.TRUE;
MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches(); MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2); MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
@ -95,7 +95,7 @@ public class MethodMatchersTests {
} }
@Test @Test
public void testStaticMethodMatcherUnion() throws Exception { void testStaticMethodMatcherUnion() {
MethodMatcher getterMatcher = new StartsWithMatcher("get"); MethodMatcher getterMatcher = new StartsWithMatcher("get");
MethodMatcher setterMatcher = new StartsWithMatcher("set"); MethodMatcher setterMatcher = new StartsWithMatcher("set");
MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher); MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher);
@ -107,7 +107,7 @@ public class MethodMatchersTests {
} }
@Test @Test
public void testUnionEquals() { void testUnionEquals() {
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE); MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher(); MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();
assertThat(first).isEqualTo(second); assertThat(first).isEqualTo(second);

18
spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class PointcutsTests { class PointcutsTests {
public static Method TEST_BEAN_SET_AGE; public static Method TEST_BEAN_SET_AGE;
public static Method TEST_BEAN_GET_AGE; public static Method TEST_BEAN_GET_AGE;
@ -120,7 +120,7 @@ public class PointcutsTests {
@Test @Test
public void testTrue() { void testTrue() {
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, 6)).isTrue(); assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, 6)).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)).isTrue(); assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue(); assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
@ -130,7 +130,7 @@ public class PointcutsTests {
} }
@Test @Test
public void testMatches() { void testMatches() {
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, 6)).isTrue(); assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, 6)).isTrue();
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse(); assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse(); assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
@ -143,7 +143,7 @@ public class PointcutsTests {
* Should match all setters and getters on any class * Should match all setters and getters on any class
*/ */
@Test @Test
public void testUnionOfSettersAndGetters() { void testUnionOfSettersAndGetters() {
Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut); Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut);
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, 6)).isTrue(); assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, 6)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue(); assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
@ -151,7 +151,7 @@ public class PointcutsTests {
} }
@Test @Test
public void testUnionOfSpecificGetters() { void testUnionOfSpecificGetters() {
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut); Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, 6)).isFalse(); assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, 6)).isFalse();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue(); assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
@ -175,7 +175,7 @@ public class PointcutsTests {
* Second one matches all getters in the MyTestBean class. TestBean getters shouldn't pass. * Second one matches all getters in the MyTestBean class. TestBean getters shouldn't pass.
*/ */
@Test @Test
public void testUnionOfAllSettersAndSubclassSetters() { void testUnionOfAllSettersAndSubclassSetters() {
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, 6)).isFalse(); assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, 6)).isFalse();
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, 6)).isTrue(); assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, 6)).isTrue();
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse(); assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
@ -193,7 +193,7 @@ public class PointcutsTests {
* it's the union of allClassGetAge and subclass getters * it's the union of allClassGetAge and subclass getters
*/ */
@Test @Test
public void testIntersectionOfSpecificGettersAndSubclassGetters() { void testIntersectionOfSpecificGettersAndSubclassGetters() {
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class)).isTrue(); assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue(); assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse(); assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
@ -239,7 +239,7 @@ public class PointcutsTests {
* The intersection of these two pointcuts leaves nothing. * The intersection of these two pointcuts leaves nothing.
*/ */
@Test @Test
public void testSimpleIntersection() { void testSimpleIntersection() {
Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut); Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut);
assertThat(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, 6)).isFalse(); assertThat(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, 6)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse(); assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();

10
spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,14 +36,14 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class RegexpMethodPointcutAdvisorIntegrationTests { class RegexpMethodPointcutAdvisorIntegrationTests {
private static final Resource CONTEXT = private static final Resource CONTEXT =
qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml"); qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
@Test @Test
public void testSinglePattern() throws Throwable { void testSinglePattern() throws Throwable {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
ITestBean advised = (ITestBean) bf.getBean("settersAdvised"); ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
@ -62,7 +62,7 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
} }
@Test @Test
public void testMultiplePatterns() throws Throwable { void testMultiplePatterns() throws Throwable {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class // This is a CGLIB proxy, so we can proxy it to the target class
@ -86,7 +86,7 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
} }
@Test @Test
public void testSerialization() throws Throwable { void testSerialization() throws Throwable {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class // This is a CGLIB proxy, so we can proxy it to the target class

6
spring-aop/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceProxyTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,13 +30,13 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class CommonsPool2TargetSourceProxyTests { class CommonsPool2TargetSourceProxyTests {
private static final Resource CONTEXT = private static final Resource CONTEXT =
qualifiedResource(CommonsPool2TargetSourceProxyTests.class, "context.xml"); qualifiedResource(CommonsPool2TargetSourceProxyTests.class, "context.xml");
@Test @Test
public void testProxy() throws Exception { void testProxy() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(CONTEXT); reader.loadBeanDefinitions(CONTEXT);

12
spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class HotSwappableTargetSourceTests { class HotSwappableTargetSourceTests {
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
@ -68,7 +68,7 @@ public class HotSwappableTargetSourceTests {
* Check it works like a normal invoker * Check it works like a normal invoker
*/ */
@Test @Test
public void testBasicFunctionality() { void testBasicFunctionality() {
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable"); SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
assertThat(proxied.getCount()).isEqualTo(INITIAL_COUNT); assertThat(proxied.getCount()).isEqualTo(INITIAL_COUNT);
proxied.doWork(); proxied.doWork();
@ -80,7 +80,7 @@ public class HotSwappableTargetSourceTests {
} }
@Test @Test
public void testValidSwaps() { void testValidSwaps() {
SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1"); SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2"); SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
@ -107,7 +107,7 @@ public class HotSwappableTargetSourceTests {
} }
@Test @Test
public void testRejectsSwapToNull() { void testRejectsSwapToNull() {
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper"); HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
assertThatIllegalArgumentException().as("Shouldn't be able to swap to invalid value").isThrownBy(() -> assertThatIllegalArgumentException().as("Shouldn't be able to swap to invalid value").isThrownBy(() ->
swapper.swap(null)) swapper.swap(null))
@ -117,7 +117,7 @@ public class HotSwappableTargetSourceTests {
} }
@Test @Test
public void testSerialization() throws Exception { void testSerialization() throws Exception {
SerializablePerson sp1 = new SerializablePerson(); SerializablePerson sp1 = new SerializablePerson();
sp1.setName("Tony"); sp1.setName("Tony");
SerializablePerson sp2 = new SerializablePerson(); SerializablePerson sp2 = new SerializablePerson();

6
spring-aop/src/test/java/org/springframework/aop/target/LazyCreationTargetSourceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class LazyCreationTargetSourceTests { class LazyCreationTargetSourceTests {
@Test @Test
public void testCreateLazy() { void testCreateLazy() {
TargetSource targetSource = new AbstractLazyCreationTargetSource() { TargetSource targetSource = new AbstractLazyCreationTargetSource() {
@Override @Override
protected Object createObject() { protected Object createObject() {

14
spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class PrototypeBasedTargetSourceTests { class PrototypeBasedTargetSourceTests {
@Test @Test
public void testSerializability() throws Exception { void testSerializability() throws Exception {
MutablePropertyValues tsPvs = new MutablePropertyValues(); MutablePropertyValues tsPvs = new MutablePropertyValues();
tsPvs.add("targetBeanName", "person"); tsPvs.add("targetBeanName", "person");
RootBeanDefinition tsBd = new RootBeanDefinition(TestTargetSource.class); RootBeanDefinition tsBd = new RootBeanDefinition(TestTargetSource.class);
@ -56,10 +56,8 @@ public class PrototypeBasedTargetSourceTests {
TestTargetSource cpts = (TestTargetSource) bf.getBean("ts"); TestTargetSource cpts = (TestTargetSource) bf.getBean("ts");
TargetSource serialized = SerializationTestUtils.serializeAndDeserialize(cpts); TargetSource serialized = SerializationTestUtils.serializeAndDeserialize(cpts);
boolean condition = serialized instanceof SingletonTargetSource; assertThat(serialized).isInstanceOfSatisfying(SingletonTargetSource.class,
assertThat(condition).as("Changed to SingletonTargetSource on deserialization").isTrue(); sts -> assertThat(sts.getTarget()).isNotNull());
SingletonTargetSource sts = (SingletonTargetSource) serialized;
assertThat(sts.getTarget()).isNotNull();
} }
@ -72,7 +70,7 @@ public class PrototypeBasedTargetSourceTests {
* state can't prevent serialization from working * state can't prevent serialization from working
*/ */
@SuppressWarnings({"unused", "serial"}) @SuppressWarnings({"unused", "serial"})
private TestBean thisFieldIsNotSerializable = new TestBean(); private final TestBean thisFieldIsNotSerializable = new TestBean();
@Override @Override
public Object getTarget() { public Object getTarget() {

6
spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class PrototypeTargetSourceTests { class PrototypeTargetSourceTests {
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
@ -52,7 +52,7 @@ public class PrototypeTargetSourceTests {
* With the singleton, there will be change. * With the singleton, there will be change.
*/ */
@Test @Test
public void testPrototypeAndSingletonBehaveDifferently() { void testPrototypeAndSingletonBehaveDifferently() {
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton"); SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
assertThat(singleton.getCount()).isEqualTo(INITIAL_COUNT); assertThat(singleton.getCount()).isEqualTo(INITIAL_COUNT);
singleton.doWork(); singleton.doWork();

14
spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ThreadLocalTargetSourceTests { class ThreadLocalTargetSourceTests {
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
@ -60,7 +60,7 @@ public class ThreadLocalTargetSourceTests {
* with one another. * with one another.
*/ */
@Test @Test
public void testUseDifferentManagedInstancesInSameThread() { void testUseDifferentManagedInstancesInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment"); SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT); assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork(); apartment.doWork();
@ -72,7 +72,7 @@ public class ThreadLocalTargetSourceTests {
} }
@Test @Test
public void testReuseInSameThread() { void testReuseInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment"); SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT); assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork(); apartment.doWork();
@ -86,7 +86,7 @@ public class ThreadLocalTargetSourceTests {
* Relies on introduction. * Relies on introduction.
*/ */
@Test @Test
public void testCanGetStatsViaMixin() { void testCanGetStatsViaMixin() {
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment"); ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
// +1 because creating target for stats call counts // +1 because creating target for stats call counts
assertThat(stats.getInvocationCount()).isEqualTo(1); assertThat(stats.getInvocationCount()).isEqualTo(1);
@ -104,7 +104,7 @@ public class ThreadLocalTargetSourceTests {
} }
@Test @Test
public void testNewThreadHasOwnInstance() throws InterruptedException { void testNewThreadHasOwnInstance() throws InterruptedException {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment"); SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT); assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork(); apartment.doWork();
@ -144,7 +144,7 @@ public class ThreadLocalTargetSourceTests {
* Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE. * Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE.
*/ */
@Test @Test
public void testReuseDestroyedTarget() { void testReuseDestroyedTarget() {
ThreadLocalTargetSource source = (ThreadLocalTargetSource)this.beanFactory.getBean("threadLocalTs"); ThreadLocalTargetSource source = (ThreadLocalTargetSource)this.beanFactory.getBean("threadLocalTs");
// try first time // try first time

10
spring-aop/src/test/java/org/springframework/aop/target/dynamic/RefreshableTargetSourceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,13 +27,13 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @author Rob Harrop * @author Rob Harrop
* @author Chris Beams * @author Chris Beams
*/ */
public class RefreshableTargetSourceTests { class RefreshableTargetSourceTests {
/** /**
* Test what happens when checking for refresh but not refreshing object. * Test what happens when checking for refresh but not refreshing object.
*/ */
@Test @Test
public void testRefreshCheckWithNonRefresh() throws Exception { void testRefreshCheckWithNonRefresh() throws Exception {
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(); CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource();
ts.setRefreshCheckDelay(0); ts.setRefreshCheckDelay(0);
@ -49,7 +49,7 @@ public class RefreshableTargetSourceTests {
* Test what happens when checking for refresh and refresh occurs. * Test what happens when checking for refresh and refresh occurs.
*/ */
@Test @Test
public void testRefreshCheckWithRefresh() throws Exception { void testRefreshCheckWithRefresh() throws Exception {
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true); CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
ts.setRefreshCheckDelay(0); ts.setRefreshCheckDelay(0);
@ -65,7 +65,7 @@ public class RefreshableTargetSourceTests {
* Test what happens when no refresh occurs. * Test what happens when no refresh occurs.
*/ */
@Test @Test
public void testWithNoRefreshCheck() throws Exception { void testWithNoRefreshCheck() {
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true); CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
ts.setRefreshCheckDelay(-1); ts.setRefreshCheckDelay(-1);

31
spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/aspectj/CommonExpressions.java

@ -0,0 +1,31 @@
/*
* Copyright 2002-2024 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.testfixture.aspectj;
/**
* Common expressions that are used in tests.
*
* @author Stephane Nicoll
*/
public class CommonExpressions {
/**
* An expression pointcut that matches all methods
*/
public static final String MATCH_ALL_METHODS = "execution(* *(..))";
}
Loading…
Cancel
Save