use of cn.taketoday.aop.testfixture.advice.MyThrowsHandler in project today-infrastructure by TAKETODAY.
the class AbstractAopProxyTests method testAddThrowsAdviceWithoutAdvisor.
@Test
public void testAddThrowsAdviceWithoutAdvisor() throws Throwable {
// Reacts to ServletException and RemoteException
MyThrowsHandler th = new MyThrowsHandler();
Echo target = new Echo();
target.setA(16);
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(new NopInterceptor());
pf.addAdvice(th);
IEcho proxied = (IEcho) createProxy(pf);
assertThat(th.getCalls()).isEqualTo(0);
assertThat(proxied.getA()).isEqualTo(target.getA());
assertThat(th.getCalls()).isEqualTo(0);
Exception ex = new Exception();
// Will be advised but doesn't match
assertThatExceptionOfType(Exception.class).isThrownBy(() -> proxied.echoException(1, ex)).matches(ex::equals);
// Subclass of RemoteException
MarshalException mex = new MarshalException("");
assertThatExceptionOfType(MarshalException.class).isThrownBy(() -> proxied.echoException(1, mex)).matches(mex::equals);
assertThat(th.getCalls("remoteException")).isEqualTo(1);
}
use of cn.taketoday.aop.testfixture.advice.MyThrowsHandler in project today-infrastructure by TAKETODAY.
the class ThrowsAdviceInterceptorTests method testNoHandlerMethodForThrowable.
@Test
public void testNoHandlerMethodForThrowable() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
Exception ex = new Exception();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willThrow(ex);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
assertThat(th.getCalls()).isEqualTo(0);
}
use of cn.taketoday.aop.testfixture.advice.MyThrowsHandler in project today-infrastructure by TAKETODAY.
the class ThrowsAdviceInterceptorTests method testNotInvoked.
@Test
public void testNotInvoked() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
Object ret = new Object();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willReturn(ret);
assertThat(ti.invoke(mi)).isEqualTo(ret);
assertThat(th.getCalls()).isEqualTo(0);
}
use of cn.taketoday.aop.testfixture.advice.MyThrowsHandler in project today-framework by TAKETODAY.
the class ThrowsAdviceInterceptorTests method testNotInvoked.
@Test
public void testNotInvoked() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
Object ret = new Object();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willReturn(ret);
assertThat(ti.invoke(mi)).isEqualTo(ret);
assertThat(th.getCalls()).isEqualTo(0);
}
use of cn.taketoday.aop.testfixture.advice.MyThrowsHandler in project today-framework by TAKETODAY.
the class ThrowsAdviceInterceptorTests method testNoHandlerMethodForThrowable.
@Test
public void testNoHandlerMethodForThrowable() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
Exception ex = new Exception();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willThrow(ex);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
assertThat(th.getCalls()).isEqualTo(0);
}
Aggregations