11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2323
2424import org .aopalliance .intercept .MethodInterceptor ;
2525import org .aopalliance .intercept .MethodInvocation ;
26- import org .aspectj .weaver .tools .PointcutExpression ;
27- import org .aspectj .weaver .tools .PointcutPrimitive ;
28- import org .aspectj .weaver .tools .UnsupportedPointcutPrimitiveException ;
2926import org .junit .jupiter .api .BeforeEach ;
3027import org .junit .jupiter .api .Test ;
3128import test .annotation .EmptySpringAnnotation ;
4239import org .springframework .beans .testfixture .beans .subpkg .DeepBean ;
4340
4441import static org .assertj .core .api .Assertions .assertThat ;
45- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
4642import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
4743import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
4844
@@ -65,7 +61,7 @@ public class AspectJExpressionPointcutTests {
6561
6662
6763 @ BeforeEach
68- public void setUp () throws NoSuchMethodException {
64+ public void setup () throws NoSuchMethodException {
6965 getAge = TestBean .class .getMethod ("getAge" );
7066 setAge = TestBean .class .getMethod ("setAge" , int .class );
7167 setSomeNumber = TestBean .class .getMethod ("setSomeNumber" , Number .class );
@@ -175,25 +171,25 @@ private void testWithinPackage(boolean matchSubpackages) throws SecurityExceptio
175171 @ Test
176172 public void testFriendlyErrorOnNoLocationClassMatching () {
177173 AspectJExpressionPointcut pc = new AspectJExpressionPointcut ();
178- assertThatIllegalStateException (). isThrownBy (() ->
179- pc .matches (ITestBean .class ))
180- .withMessageContaining ("expression" );
174+ assertThatIllegalStateException ()
175+ . isThrownBy (() -> pc . getClassFilter () .matches (ITestBean .class ))
176+ .withMessageContaining ("expression" );
181177 }
182178
183179 @ Test
184180 public void testFriendlyErrorOnNoLocation2ArgMatching () {
185181 AspectJExpressionPointcut pc = new AspectJExpressionPointcut ();
186- assertThatIllegalStateException (). isThrownBy (() ->
187- pc .matches (getAge , ITestBean .class ))
188- .withMessageContaining ("expression" );
182+ assertThatIllegalStateException ()
183+ . isThrownBy (() -> pc . getMethodMatcher () .matches (getAge , ITestBean .class ))
184+ .withMessageContaining ("expression" );
189185 }
190186
191187 @ Test
192188 public void testFriendlyErrorOnNoLocation3ArgMatching () {
193189 AspectJExpressionPointcut pc = new AspectJExpressionPointcut ();
194- assertThatIllegalStateException (). isThrownBy (() ->
195- pc .matches (getAge , ITestBean .class , (Object []) null ))
196- .withMessageContaining ("expression" );
190+ assertThatIllegalStateException ()
191+ . isThrownBy (() -> pc . getMethodMatcher () .matches (getAge , ITestBean .class , (Object []) null ))
192+ .withMessageContaining ("expression" );
197193 }
198194
199195
@@ -210,8 +206,10 @@ public void testMatchWithArgs() throws Exception {
210206 // not currently testable in a reliable fashion
211207 //assertDoesNotMatchStringClass(classFilter);
212208
213- assertThat (methodMatcher .matches (setSomeNumber , TestBean .class , 12D )).as ("Should match with setSomeNumber with Double input" ).isTrue ();
214- assertThat (methodMatcher .matches (setSomeNumber , TestBean .class , 11 )).as ("Should not match setSomeNumber with Integer input" ).isFalse ();
209+ assertThat (methodMatcher .matches (setSomeNumber , TestBean .class , 12D ))
210+ .as ("Should match with setSomeNumber with Double input" ).isTrue ();
211+ assertThat (methodMatcher .matches (setSomeNumber , TestBean .class , 11 ))
212+ .as ("Should not match setSomeNumber with Integer input" ).isFalse ();
215213 assertThat (methodMatcher .matches (getAge , TestBean .class )).as ("Should not match getAge" ).isFalse ();
216214 assertThat (methodMatcher .isRuntime ()).as ("Should be a runtime match" ).isTrue ();
217215 }
@@ -246,14 +244,13 @@ public void testDynamicMatchingProxy() {
246244 @ Test
247245 public void testInvalidExpression () {
248246 String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)" ;
249- assertThatIllegalArgumentException ().isThrownBy (
250- getPointcut (expression )::getClassFilter ); // call to getClassFilter forces resolution
247+ assertThatIllegalArgumentException ().isThrownBy (() -> getPointcut (expression ).getClassFilter ().matches (Object .class ));
251248 }
252249
253250 private TestBean getAdvisedProxy (String pointcutExpression , CallCountingInterceptor interceptor ) {
254251 TestBean target = new TestBean ();
255252
256- Pointcut pointcut = getPointcut (pointcutExpression );
253+ AspectJExpressionPointcut pointcut = getPointcut (pointcutExpression );
257254
258255 DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor ();
259256 advisor .setAdvice (interceptor );
@@ -277,40 +274,29 @@ private void assertMatchesTestBeanClass(ClassFilter classFilter) {
277274 @ Test
278275 public void testWithUnsupportedPointcutPrimitive () {
279276 String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())" ;
280- assertThatExceptionOfType (UnsupportedPointcutPrimitiveException .class ).isThrownBy (() ->
281- getPointcut (expression ).getClassFilter ()) // call to getClassFilter forces resolution...
282- .satisfies (ex -> assertThat (ex .getUnsupportedPrimitive ()).isEqualTo (PointcutPrimitive .CALL ));
277+ assertThat (getPointcut (expression ).getClassFilter ().matches (Object .class )).isFalse ();
283278 }
284279
285280 @ Test
286281 public void testAndSubstitution () {
287- Pointcut pc = getPointcut ("execution(* *(..)) and args(String)" );
288- PointcutExpression expr = (( AspectJExpressionPointcut ) pc ).getPointcutExpression ();
289- assertThat (expr . getPointcutExpression () ).isEqualTo ("execution(* *(..)) && args(String)" );
282+ AspectJExpressionPointcut pc = getPointcut ("execution(* *(..)) and args(String)" );
283+ String expr = pc . getPointcutExpression ( ).getPointcutExpression ();
284+ assertThat (expr ).isEqualTo ("execution(* *(..)) && args(String)" );
290285 }
291286
292287 @ Test
293288 public void testMultipleAndSubstitutions () {
294- Pointcut pc = getPointcut ("execution(* *(..)) and args(String) and this(Object)" );
295- PointcutExpression expr = (( AspectJExpressionPointcut ) pc ).getPointcutExpression ();
296- assertThat (expr . getPointcutExpression () ).isEqualTo ("execution(* *(..)) && args(String) && this(Object)" );
289+ AspectJExpressionPointcut pc = getPointcut ("execution(* *(..)) and args(String) and this(Object)" );
290+ String expr = pc . getPointcutExpression ( ).getPointcutExpression ();
291+ assertThat (expr ).isEqualTo ("execution(* *(..)) && args(String) && this(Object)" );
297292 }
298293
299- private Pointcut getPointcut (String expression ) {
294+ private AspectJExpressionPointcut getPointcut (String expression ) {
300295 AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut ();
301296 pointcut .setExpression (expression );
302297 return pointcut ;
303298 }
304299
305-
306- public static class OtherIOther implements IOther {
307-
308- @ Override
309- public void absquatulate () {
310- // Empty
311- }
312- }
313-
314300 @ Test
315301 public void testMatchGenericArgument () {
316302 String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )" ;
@@ -505,6 +491,15 @@ public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
505491 }
506492
507493
494+ public static class OtherIOther implements IOther {
495+
496+ @ Override
497+ public void absquatulate () {
498+ // Empty
499+ }
500+ }
501+
502+
508503 public static class HasGeneric {
509504
510505 public void setFriends (List <TestBean > friends ) {
0 commit comments