1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 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.
@@ -203,7 +203,6 @@ void perThisAspect() throws Exception {
203
203
itb .getSpouse ();
204
204
205
205
assertThat (maaif .isMaterialized ()).isTrue ();
206
-
207
206
assertThat (imapa .getDeclaredPointcut ().getMethodMatcher ().matches (TestBean .class .getMethod ("getAge" ), null )).isTrue ();
208
207
209
208
assertThat (itb .getAge ()).as ("Around advice must apply" ).isEqualTo (0 );
@@ -301,7 +300,7 @@ void bindingWithSingleArg() {
301
300
void bindingWithMultipleArgsDifferentlyOrdered () {
302
301
ManyValuedArgs target = new ManyValuedArgs ();
303
302
ManyValuedArgs mva = createProxy (target , ManyValuedArgs .class ,
304
- getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new ManyValuedArgs (), "someBean" )));
303
+ getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new ManyValuedArgs (), "someBean" )));
305
304
306
305
String a = "a" ;
307
306
int b = 12 ;
@@ -320,7 +319,7 @@ void introductionOnTargetNotImplementingInterface() {
320
319
NotLockable notLockableTarget = new NotLockable ();
321
320
assertThat (notLockableTarget ).isNotInstanceOf (Lockable .class );
322
321
NotLockable notLockable1 = createProxy (notLockableTarget , NotLockable .class ,
323
- getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )));
322
+ getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )));
324
323
assertThat (notLockable1 ).isInstanceOf (Lockable .class );
325
324
Lockable lockable = (Lockable ) notLockable1 ;
326
325
assertThat (lockable .locked ()).isFalse ();
@@ -329,7 +328,7 @@ void introductionOnTargetNotImplementingInterface() {
329
328
330
329
NotLockable notLockable2Target = new NotLockable ();
331
330
NotLockable notLockable2 = createProxy (notLockable2Target , NotLockable .class ,
332
- getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )));
331
+ getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )));
333
332
assertThat (notLockable2 ).isInstanceOf (Lockable .class );
334
333
Lockable lockable2 = (Lockable ) notLockable2 ;
335
334
assertThat (lockable2 .locked ()).isFalse ();
@@ -343,20 +342,19 @@ void introductionOnTargetNotImplementingInterface() {
343
342
void introductionAdvisorExcludedFromTargetImplementingInterface () {
344
343
assertThat (AopUtils .findAdvisorsThatCanApply (
345
344
getAdvisorFactory ().getAdvisors (
346
- aspectInstanceFactory (new MakeLockable (), "someBean" )),
345
+ aspectInstanceFactory (new MakeLockable (), "someBean" )),
347
346
CannotBeUnlocked .class )).isEmpty ();
348
347
assertThat (AopUtils .findAdvisorsThatCanApply (getAdvisorFactory ().getAdvisors (
349
- aspectInstanceFactory (new MakeLockable (),"someBean" )), NotLockable .class )).hasSize (2 );
348
+ aspectInstanceFactory (new MakeLockable (),"someBean" )), NotLockable .class )).hasSize (2 );
350
349
}
351
350
352
351
@ Test
353
352
void introductionOnTargetImplementingInterface () {
354
353
CannotBeUnlocked target = new CannotBeUnlocked ();
355
354
Lockable proxy = createProxy (target , CannotBeUnlocked .class ,
356
- // Ensure that we exclude
357
355
AopUtils .findAdvisorsThatCanApply (
358
- getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )),
359
- CannotBeUnlocked .class ));
356
+ getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )),
357
+ CannotBeUnlocked .class ));
360
358
assertThat (proxy ).isInstanceOf (Lockable .class );
361
359
Lockable lockable = proxy ;
362
360
assertThat (lockable .locked ()).as ("Already locked" ).isTrue ();
@@ -370,16 +368,16 @@ void introductionOnTargetExcludedByTypePattern() {
370
368
ArrayList <Object > target = new ArrayList <>();
371
369
List <?> proxy = createProxy (target , List .class ,
372
370
AopUtils .findAdvisorsThatCanApply (
373
- getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )),
374
- List .class ));
371
+ getAdvisorFactory ().getAdvisors (aspectInstanceFactory (new MakeLockable (), "someBean" )),
372
+ List .class ));
375
373
assertThat (proxy ).as ("Type pattern must have excluded mixin" ).isNotInstanceOf (Lockable .class );
376
374
}
377
375
378
376
@ Test
379
377
void introductionBasedOnAnnotationMatch () { // gh-9980
380
378
AnnotatedTarget target = new AnnotatedTargetImpl ();
381
379
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (
382
- aspectInstanceFactory (new MakeAnnotatedTypeModifiable (), "someBean" ));
380
+ aspectInstanceFactory (new MakeAnnotatedTypeModifiable (), "someBean" ));
383
381
Object proxy = createProxy (target , AnnotatedTarget .class , advisors );
384
382
assertThat (proxy ).isInstanceOf (Lockable .class );
385
383
Lockable lockable = (Lockable ) proxy ;
@@ -393,9 +391,9 @@ void introductionWithArgumentBinding() {
393
391
TestBean target = new TestBean ();
394
392
395
393
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (
396
- aspectInstanceFactory (new MakeITestBeanModifiable (), "someBean" ));
394
+ aspectInstanceFactory (new MakeITestBeanModifiable (), "someBean" ));
397
395
advisors .addAll (getAdvisorFactory ().getAdvisors (
398
- aspectInstanceFactory (new MakeLockable (), "someBean" )));
396
+ aspectInstanceFactory (new MakeLockable (), "someBean" )));
399
397
400
398
Modifiable modifiable = (Modifiable ) createProxy (target , ITestBean .class , advisors );
401
399
assertThat (modifiable ).isInstanceOf (Modifiable .class );
@@ -426,7 +424,7 @@ void aspectMethodThrowsExceptionLegalOnSignature() {
426
424
TestBean target = new TestBean ();
427
425
UnsupportedOperationException expectedException = new UnsupportedOperationException ();
428
426
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (
429
- aspectInstanceFactory (new ExceptionThrowingAspect (expectedException ), "someBean" ));
427
+ aspectInstanceFactory (new ExceptionThrowingAspect (expectedException ), "someBean" ));
430
428
assertThat (advisors ).as ("One advice method was found" ).hasSize (1 );
431
429
ITestBean itb = createProxy (target , ITestBean .class , advisors );
432
430
assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (itb ::getAge );
@@ -439,20 +437,20 @@ void aspectMethodThrowsExceptionIllegalOnSignature() {
439
437
TestBean target = new TestBean ();
440
438
RemoteException expectedException = new RemoteException ();
441
439
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (
442
- aspectInstanceFactory (new ExceptionThrowingAspect (expectedException ), "someBean" ));
440
+ aspectInstanceFactory (new ExceptionThrowingAspect (expectedException ), "someBean" ));
443
441
assertThat (advisors ).as ("One advice method was found" ).hasSize (1 );
444
442
ITestBean itb = createProxy (target , ITestBean .class , advisors );
445
443
assertThatExceptionOfType (UndeclaredThrowableException .class )
446
- .isThrownBy (itb ::getAge )
447
- .withCause (expectedException );
444
+ .isThrownBy (itb ::getAge )
445
+ .withCause (expectedException );
448
446
}
449
447
450
448
@ Test
451
449
void twoAdvicesOnOneAspect () {
452
450
TestBean target = new TestBean ();
453
451
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect ();
454
452
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (
455
- aspectInstanceFactory (twoAdviceAspect , "someBean" ));
453
+ aspectInstanceFactory (twoAdviceAspect , "someBean" ));
456
454
assertThat (advisors ).as ("Two advice methods found" ).hasSize (2 );
457
455
ITestBean itb = createProxy (target , ITestBean .class , advisors );
458
456
itb .setName ("" );
@@ -466,7 +464,7 @@ void twoAdvicesOnOneAspect() {
466
464
void afterAdviceTypes () throws Exception {
467
465
InvocationTrackingAspect aspect = new InvocationTrackingAspect ();
468
466
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (
469
- aspectInstanceFactory (aspect , "exceptionHandlingAspect" ));
467
+ aspectInstanceFactory (aspect , "exceptionHandlingAspect" ));
470
468
Echo echo = createProxy (new Echo (), Echo .class , advisors );
471
469
472
470
assertThat (aspect .invocations ).isEmpty ();
@@ -475,7 +473,7 @@ void afterAdviceTypes() throws Exception {
475
473
476
474
aspect .invocations .clear ();
477
475
assertThatExceptionOfType (FileNotFoundException .class )
478
- .isThrownBy (() -> echo .echo (new FileNotFoundException ()));
476
+ .isThrownBy (() -> echo .echo (new FileNotFoundException ()));
479
477
assertThat (aspect .invocations ).containsExactly ("around - start" , "before" , "after throwing" , "after" , "around - end" );
480
478
}
481
479
@@ -487,7 +485,6 @@ void nonAbstractParentAspect() {
487
485
assertThat (Modifier .isAbstract (aspect .getClass ().getSuperclass ().getModifiers ())).isFalse ();
488
486
489
487
List <Advisor > advisors = getAdvisorFactory ().getAdvisors (aspectInstanceFactory (aspect , "incrementingAspect" ));
490
-
491
488
ITestBean proxy = createProxy (new TestBean ("Jane" , 42 ), ITestBean .class , advisors );
492
489
assertThat (proxy .getAge ()).isEqualTo (86 ); // (42 + 1) * 2
493
490
}
@@ -812,19 +809,19 @@ void before() {
812
809
invocations .add ("before" );
813
810
}
814
811
815
- @ AfterReturning ("echo()" )
816
- void afterReturning () {
817
- invocations .add ("after returning " );
812
+ @ After ("echo()" )
813
+ void after () {
814
+ invocations .add ("after" );
818
815
}
819
816
820
- @ AfterThrowing ( " echo() " )
821
- void afterThrowing ( ) {
822
- invocations .add ("after throwing " );
817
+ @ AfterReturning ( pointcut = "this(target) && execution(* echo(*))" , returning = "returnValue " )
818
+ void afterReturning ( JoinPoint joinPoint , Echo target , Object returnValue ) {
819
+ invocations .add ("after returning " );
823
820
}
824
821
825
- @ After ( " echo() " )
826
- void after ( ) {
827
- invocations .add ("after" );
822
+ @ AfterThrowing ( pointcut = "this(target) && execution(* echo(*))" , throwing = "exception " )
823
+ void afterThrowing ( JoinPoint joinPoint , Echo target , Throwable exception ) {
824
+ invocations .add ("after throwing " );
828
825
}
829
826
}
830
827
@@ -967,7 +964,7 @@ private Method getGetterFromSetter(Method setter) {
967
964
class MakeITestBeanModifiable extends AbstractMakeModifiable {
968
965
969
966
@ DeclareParents (value = "org.springframework.beans.testfixture.beans.ITestBean+" ,
970
- defaultImpl = ModifiableImpl .class )
967
+ defaultImpl = ModifiableImpl .class )
971
968
static MutableModifiable mixin ;
972
969
973
970
}
0 commit comments