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.
37
37
import org .aspectj .lang .annotation .DeclarePrecedence ;
38
38
import org .aspectj .lang .annotation .Pointcut ;
39
39
import org .aspectj .lang .reflect .MethodSignature ;
40
- import org .junit .jupiter .api .Disabled ;
41
40
import org .junit .jupiter .api .Test ;
42
41
import test .aop .DefaultLockable ;
43
42
import test .aop .Lockable ;
@@ -76,25 +75,24 @@ abstract class AbstractAspectJAdvisorFactoryTests {
76
75
77
76
/**
78
77
* To be overridden by concrete test subclasses.
79
- * @return the fixture
80
78
*/
81
79
protected abstract AspectJAdvisorFactory getFixture ();
82
80
83
81
84
82
@ Test
85
83
void rejectsPerCflowAspect () {
86
- assertThatExceptionOfType (AopConfigException .class ). isThrownBy (() ->
87
- getFixture ().getAdvisors (
84
+ assertThatExceptionOfType (AopConfigException .class )
85
+ . isThrownBy (() -> getFixture ().getAdvisors (
88
86
new SingletonMetadataAwareAspectInstanceFactory (new PerCflowAspect (), "someBean" )))
89
- .withMessageContaining ("PERCFLOW" );
87
+ .withMessageContaining ("PERCFLOW" );
90
88
}
91
89
92
90
@ Test
93
91
void rejectsPerCflowBelowAspect () {
94
- assertThatExceptionOfType (AopConfigException .class ). isThrownBy (() ->
95
- getFixture ().getAdvisors (
96
- new SingletonMetadataAwareAspectInstanceFactory (new PerCflowBelowAspect (), "someBean" )))
97
- .withMessageContaining ("PERCFLOWBELOW" );
92
+ assertThatExceptionOfType (AopConfigException .class )
93
+ . isThrownBy (() -> getFixture ().getAdvisors (
94
+ new SingletonMetadataAwareAspectInstanceFactory (new PerCflowBelowAspect (), "someBean" )))
95
+ .withMessageContaining ("PERCFLOWBELOW" );
98
96
}
99
97
100
98
@ Test
@@ -385,8 +383,7 @@ void introductionOnTargetImplementingInterface() {
385
383
assertThat (lockable .locked ()).as ("Already locked" ).isTrue ();
386
384
lockable .lock ();
387
385
assertThat (lockable .locked ()).as ("Real target ignores locking" ).isTrue ();
388
- assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (() ->
389
- lockable .unlock ());
386
+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (lockable ::unlock );
390
387
}
391
388
392
389
@ Test
@@ -413,9 +410,7 @@ void introductionBasedOnAnnotationMatch_SPR5307() {
413
410
lockable .locked ();
414
411
}
415
412
416
- // TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
417
413
@ Test
418
- @ Disabled
419
414
void introductionWithArgumentBinding () {
420
415
TestBean target = new TestBean ();
421
416
@@ -523,6 +518,16 @@ void afterAdviceTypes() throws Exception {
523
518
assertThat (aspect .invocations ).containsExactly ("around - start" , "before" , "after throwing" , "after" , "around - end" );
524
519
}
525
520
521
+ @ Test
522
+ void parentAspect () {
523
+ TestBean target = new TestBean ("Jane" , 42 );
524
+ MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory (
525
+ new IncrementingAspect (), "incrementingAspect" );
526
+ ITestBean proxy = (ITestBean ) createProxy (target ,
527
+ getFixture ().getAdvisors (aspectInstanceFactory ), ITestBean .class );
528
+ assertThat (proxy .getAge ()).isEqualTo (86 ); // (42 + 1) * 2
529
+ }
530
+
526
531
@ Test
527
532
void failureWithoutExplicitDeclarePrecedence () {
528
533
TestBean target = new TestBean ();
@@ -647,7 +652,7 @@ public int getOrder() {
647
652
static class NamedPointcutAspectWithFQN {
648
653
649
654
@ SuppressWarnings ("unused" )
650
- private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean ();
655
+ private final ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean ();
651
656
652
657
@ Pointcut ("execution(* getAge())" )
653
658
void getAge () {
@@ -767,6 +772,31 @@ Object echo(Object o) throws Exception {
767
772
}
768
773
769
774
775
+ @ Aspect
776
+ abstract static class DoublingAspect {
777
+
778
+ @ Around ("execution(* getAge())" )
779
+ public Object doubleAge (ProceedingJoinPoint pjp ) throws Throwable {
780
+ return ((int ) pjp .proceed ()) * 2 ;
781
+ }
782
+ }
783
+
784
+
785
+ @ Aspect
786
+ static class IncrementingAspect extends DoublingAspect {
787
+
788
+ @ Override
789
+ public Object doubleAge (ProceedingJoinPoint pjp ) throws Throwable {
790
+ return ((int ) pjp .proceed ()) * 2 ;
791
+ }
792
+
793
+ @ Around ("execution(* getAge())" )
794
+ public int incrementAge (ProceedingJoinPoint pjp ) throws Throwable {
795
+ return ((int ) pjp .proceed ()) + 1 ;
796
+ }
797
+ }
798
+
799
+
770
800
@ Aspect
771
801
private static class InvocationTrackingAspect {
772
802
@@ -824,7 +854,7 @@ void blowUpButDoesntMatterBecauseAroundAdviceWontLetThisBeInvoked() {
824
854
825
855
@ Around ("getAge()" )
826
856
int preventExecution (ProceedingJoinPoint pjp ) {
827
- return 666 ;
857
+ return 42 ;
828
858
}
829
859
}
830
860
@@ -844,7 +874,7 @@ void blowUpButDoesntMatterBecauseAroundAdviceWontLetThisBeInvoked() {
844
874
845
875
@ Around ("getAge()" )
846
876
int preventExecution (ProceedingJoinPoint pjp ) {
847
- return 666 ;
877
+ return 42 ;
848
878
}
849
879
}
850
880
@@ -1066,7 +1096,7 @@ class PerThisAspect {
1066
1096
1067
1097
// Just to check that this doesn't cause problems with introduction processing
1068
1098
@ SuppressWarnings ("unused" )
1069
- private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean ();
1099
+ private final ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean ();
1070
1100
1071
1101
@ Around ("execution(int *.getAge())" )
1072
1102
int returnCountAsAge () {
0 commit comments