MockInvoker implements Invoker<T> { public static Throwable getThrowable(String throwstr) { Throwable throwable = THROWABLE_MAP.get(throwstr); if (throwable != null) { return throwable; } try { Throwable t; Class<?> bizException = ReflectUtils.forName(throwstr); Constructor<?> constructor; constructor = ReflectUtils.findConstructor(bizException, String.class); t = (Throwable) constructor.newInstance(new Object[]{"mocked exception for service degradation."}); if (THROWABLE_MAP.size() < 1000) { THROWABLE_MAP.put(throwstr, t); } return t; } catch (Exception e) { throw new RpcException("mock throw error :" + throwstr + " argument error.", e); } } MockInvoker(URL url, Class<T> type); static Object parseMockValue(String mock); static Object parseMockValue(String mock, Type[] returnTypes); @Override Result invoke(Invocation invocation); static Throwable getThrowable(String throwstr); @SuppressWarnings("unchecked") static Object getMockObject(String mockService, Class serviceType); static String normalizeMock(String mock); @Override URL getUrl(); @Override boolean isAvailable(); @Override void destroy(); @Override Class<T> getInterface();  }
@Test public void testGetThrowable() { Assertions.assertThrows(RpcException.class, () -> MockInvoker.getThrowable("Exception.class")); }