ExceptionFilter implements Filter, Filter.Listener { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { return invoker.invoke(invocation); }  @Override Result invoke(Invoker<?> invoker, Invocation invocation); @Override void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation); @Override void onError(Throwable e, Invoker<?> invoker, Invocation invocation); void setLogger(Logger logger);  }
@SuppressWarnings("unchecked") @Test public void testJavaException() { ExceptionFilter exceptionFilter = new ExceptionFilter(); RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[]{String.class}, new Object[]{"world"}); AppResponse appResponse = new AppResponse(); appResponse.setException(new IllegalArgumentException("java")); Invoker<DemoService> invoker = mock(Invoker.class); when(invoker.invoke(invocation)).thenReturn(appResponse); when(invoker.getInterface()).thenReturn(DemoService.class); Result newResult = exceptionFilter.invoke(invoker, invocation); Assertions.assertEquals(appResponse.getException(), newResult.getException()); }
@SuppressWarnings("unchecked") @Test public void testRuntimeException() { ExceptionFilter exceptionFilter = new ExceptionFilter(); RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[]{String.class}, new Object[]{"world"}); AppResponse appResponse = new AppResponse(); appResponse.setException(new LocalException("localException")); Invoker<DemoService> invoker = mock(Invoker.class); when(invoker.invoke(invocation)).thenReturn(appResponse); when(invoker.getInterface()).thenReturn(DemoService.class); Result newResult = exceptionFilter.invoke(invoker, invocation); Assertions.assertEquals(appResponse.getException(), newResult.getException()); }