use of cn.taketoday.aop.AfterReturningAdvice in project today-infrastructure by TAKETODAY.
the class AbstractAopProxyTests method testAfterReturningAdvisorIsInvoked.
@Test
public void testAfterReturningAdvisorIsInvoked() {
class SummingAfterAdvice implements AfterReturningAdvice {
public int sum;
@Override
public void afterReturning(Object returnValue, MethodInvocation invocation) throws Throwable {
sum += ((Integer) returnValue).intValue();
}
}
SummingAfterAdvice aa = new SummingAfterAdvice();
@SuppressWarnings("serial") Advisor matchesInt = new StaticMethodMatcherPointcutAdvisor(aa) {
@Override
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getReturnType() == int.class;
}
};
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(new NopInterceptor());
pf.addAdvisor(matchesInt);
assertThat(pf.getAdvisors()[1]).as("Advisor was added").isEqualTo(matchesInt);
ITestBean proxied = (ITestBean) createProxy(pf);
assertThat(aa.sum).isEqualTo(0);
int i1 = 12;
int i2 = 13;
// Won't be advised
proxied.setAge(i1);
assertThat(proxied.getAge()).isEqualTo(i1);
assertThat(aa.sum).isEqualTo(i1);
proxied.setAge(i2);
assertThat(proxied.getAge()).isEqualTo(i2);
assertThat(aa.sum).isEqualTo((i1 + i2));
assertThat(proxied.getAge()).isEqualTo(i2);
}
use of cn.taketoday.aop.AfterReturningAdvice in project today-infrastructure by TAKETODAY.
the class AspectJPrecedenceComparatorTests method createSpringAOPAfterAdvice.
private Advisor createSpringAOPAfterAdvice(int order) {
AfterReturningAdvice advice = (returnValue, method) -> {
};
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
advisor.setOrder(order);
return advisor;
}
use of cn.taketoday.aop.AfterReturningAdvice in project today-framework by TAKETODAY.
the class AbstractAopProxyTests method testAfterReturningAdvisorIsInvoked.
@Test
public void testAfterReturningAdvisorIsInvoked() {
class SummingAfterAdvice implements AfterReturningAdvice {
public int sum;
@Override
public void afterReturning(Object returnValue, MethodInvocation invocation) throws Throwable {
sum += ((Integer) returnValue).intValue();
}
}
SummingAfterAdvice aa = new SummingAfterAdvice();
@SuppressWarnings("serial") Advisor matchesInt = new StaticMethodMatcherPointcutAdvisor(aa) {
@Override
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getReturnType() == int.class;
}
};
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(new NopInterceptor());
pf.addAdvisor(matchesInt);
assertThat(pf.getAdvisors()[1]).as("Advisor was added").isEqualTo(matchesInt);
ITestBean proxied = (ITestBean) createProxy(pf);
assertThat(aa.sum).isEqualTo(0);
int i1 = 12;
int i2 = 13;
// Won't be advised
proxied.setAge(i1);
assertThat(proxied.getAge()).isEqualTo(i1);
assertThat(aa.sum).isEqualTo(i1);
proxied.setAge(i2);
assertThat(proxied.getAge()).isEqualTo(i2);
assertThat(aa.sum).isEqualTo((i1 + i2));
assertThat(proxied.getAge()).isEqualTo(i2);
}
use of cn.taketoday.aop.AfterReturningAdvice in project today-framework by TAKETODAY.
the class AspectJPrecedenceComparatorTests method createSpringAOPAfterAdvice.
private Advisor createSpringAOPAfterAdvice(int order) {
AfterReturningAdvice advice = (returnValue, method) -> {
};
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
advisor.setOrder(order);
return advisor;
}
use of cn.taketoday.aop.AfterReturningAdvice in project today-framework by TAKETODAY.
the class AbstractAopProxyTests method testAfterReturningAdvisorIsInvoked.
@Test
public void testAfterReturningAdvisorIsInvoked() {
class SummingAfterAdvice implements AfterReturningAdvice {
public int sum;
@Override
public void afterReturning(Object returnValue, MethodInvocation invocation) throws Throwable {
sum += ((Integer) returnValue).intValue();
}
}
SummingAfterAdvice aa = new SummingAfterAdvice();
@SuppressWarnings("serial") Advisor matchesInt = new StaticMethodMatcherPointcutAdvisor(aa) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
return m.getReturnType() == int.class;
}
};
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(new NopInterceptor());
pf.addAdvisor(matchesInt);
assertThat(pf.getAdvisors()[1]).as("Advisor was added").isEqualTo(matchesInt);
ITestBean proxied = (ITestBean) createProxy(pf);
assertThat(aa.sum).isEqualTo(0);
int i1 = 12;
int i2 = 13;
// Won't be advised
proxied.setAge(i1);
assertThat(proxied.getAge()).isEqualTo(i1);
assertThat(aa.sum).isEqualTo(i1);
proxied.setAge(i2);
assertThat(proxied.getAge()).isEqualTo(i2);
assertThat(aa.sum).isEqualTo((i1 + i2));
assertThat(proxied.getAge()).isEqualTo(i2);
}
Aggregations