Allow @Aspect classes to extend concrete @Aspect classes

Closes gh-29830
This commit is contained in:
Sam Brannen
2023-01-18 14:35:38 +01:00
parent e4b25ab480
commit c3d123fef7
2 changed files with 35 additions and 10 deletions

View File

@@ -482,6 +482,19 @@ abstract class AbstractAspectJAdvisorFactoryTests {
assertThat(aspect.invocations).containsExactly("around - start", "before", "after throwing", "after", "around - end");
}
@Test
void nonAbstractParentAspect() throws Exception {
IncrementingAspect aspect = new IncrementingAspect();
// Precondition:
assertThat(Modifier.isAbstract(aspect.getClass().getSuperclass().getModifiers())).isFalse();
List<Advisor> advisors = getAdvisorFactory().getAdvisors(aspectInstanceFactory(aspect, "incrementingAspect"));
ITestBean proxy = createProxy(new TestBean("Jane", 42), ITestBean.class, advisors);
assertThat(proxy.getAge()).isEqualTo(86); // (42 + 1) * 2
}
@Test
void failureWithoutExplicitDeclarePrecedence() {
TestBean target = new TestBean();
@@ -748,6 +761,26 @@ abstract class AbstractAspectJAdvisorFactoryTests {
}
@Aspect
class DoublingAspect {
@Around("execution(* getAge())")
public Object doubleAge(ProceedingJoinPoint pjp) throws Throwable {
return ((int) pjp.proceed()) * 2;
}
}
@Aspect
class IncrementingAspect extends DoublingAspect {
@Around("execution(* getAge())")
public int incrementAge(ProceedingJoinPoint pjp) throws Throwable {
return ((int) pjp.proceed()) + 1;
}
}
@Aspect
private static class InvocationTrackingAspect {