1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
24
24
import org .aopalliance .intercept .MethodInterceptor ;
25
25
import 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 ;
29
26
import org .junit .jupiter .api .BeforeEach ;
30
27
import org .junit .jupiter .api .Test ;
31
28
import test .annotation .EmptySpringAnnotation ;
42
39
import org .springframework .beans .testfixture .beans .subpkg .DeepBean ;
43
40
44
41
import static org .assertj .core .api .Assertions .assertThat ;
45
- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
46
42
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
47
43
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
48
44
@@ -65,7 +61,7 @@ public class AspectJExpressionPointcutTests {
65
61
66
62
67
63
@ BeforeEach
68
- public void setUp () throws NoSuchMethodException {
64
+ public void setup () throws NoSuchMethodException {
69
65
getAge = TestBean .class .getMethod ("getAge" );
70
66
setAge = TestBean .class .getMethod ("setAge" , int .class );
71
67
setSomeNumber = TestBean .class .getMethod ("setSomeNumber" , Number .class );
@@ -175,25 +171,25 @@ private void testWithinPackage(boolean matchSubpackages) throws SecurityExceptio
175
171
@ Test
176
172
public void testFriendlyErrorOnNoLocationClassMatching () {
177
173
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" );
181
177
}
182
178
183
179
@ Test
184
180
public void testFriendlyErrorOnNoLocation2ArgMatching () {
185
181
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" );
189
185
}
190
186
191
187
@ Test
192
188
public void testFriendlyErrorOnNoLocation3ArgMatching () {
193
189
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" );
197
193
}
198
194
199
195
@@ -210,8 +206,10 @@ public void testMatchWithArgs() throws Exception {
210
206
// not currently testable in a reliable fashion
211
207
//assertDoesNotMatchStringClass(classFilter);
212
208
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 ();
215
213
assertThat (methodMatcher .matches (getAge , TestBean .class )).as ("Should not match getAge" ).isFalse ();
216
214
assertThat (methodMatcher .isRuntime ()).as ("Should be a runtime match" ).isTrue ();
217
215
}
@@ -246,14 +244,13 @@ public void testDynamicMatchingProxy() {
246
244
@ Test
247
245
public void testInvalidExpression () {
248
246
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 ));
251
248
}
252
249
253
250
private TestBean getAdvisedProxy (String pointcutExpression , CallCountingInterceptor interceptor ) {
254
251
TestBean target = new TestBean ();
255
252
256
- Pointcut pointcut = getPointcut (pointcutExpression );
253
+ AspectJExpressionPointcut pointcut = getPointcut (pointcutExpression );
257
254
258
255
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor ();
259
256
advisor .setAdvice (interceptor );
@@ -277,40 +274,29 @@ private void assertMatchesTestBeanClass(ClassFilter classFilter) {
277
274
@ Test
278
275
public void testWithUnsupportedPointcutPrimitive () {
279
276
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 ();
283
278
}
284
279
285
280
@ Test
286
281
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)" );
290
285
}
291
286
292
287
@ Test
293
288
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)" );
297
292
}
298
293
299
- private Pointcut getPointcut (String expression ) {
294
+ private AspectJExpressionPointcut getPointcut (String expression ) {
300
295
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut ();
301
296
pointcut .setExpression (expression );
302
297
return pointcut ;
303
298
}
304
299
305
-
306
- public static class OtherIOther implements IOther {
307
-
308
- @ Override
309
- public void absquatulate () {
310
- // Empty
311
- }
312
- }
313
-
314
300
@ Test
315
301
public void testMatchGenericArgument () {
316
302
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )" ;
@@ -505,6 +491,15 @@ public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
505
491
}
506
492
507
493
494
+ public static class OtherIOther implements IOther {
495
+
496
+ @ Override
497
+ public void absquatulate () {
498
+ // Empty
499
+ }
500
+ }
501
+
502
+
508
503
public static class HasGeneric {
509
504
510
505
public void setFriends (List <TestBean > friends ) {
0 commit comments