@Test public void failCountDown() throws Exception { DummyService target = new DummyServiceImpl(); DummyService dummyService = FlakyProxy.newJdkProxy(target, FlakinessFunction.failCountDown(1)); try { dummyService.countWords(parsedPage); fail("UncheckedIOException expected"); } catch (UncheckedIOException e) { assertThat(e.getCause(), instanceOf(IOException.class)); } dummyService.countWords(parsedPage); dummyService.countWords(parsedPage); }
public static <T> T newJdkProxy(Object obj, FlakinessFunction flakinessFunction) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); return (T) java.lang.reflect.Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new FlakyProxy(obj, flakinessFunction)); }
FlakyProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj, FlakinessFunction flakinessFunction) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); return (T) java.lang.reflect.Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new FlakyProxy(obj, flakinessFunction)); } }
FlakyProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj, FlakinessFunction flakinessFunction) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); return (T) java.lang.reflect.Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new FlakyProxy(obj, flakinessFunction)); } private  FlakyProxy(Object obj, FlakinessFunction flakinessFunction); }
FlakyProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj, FlakinessFunction flakinessFunction) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); return (T) java.lang.reflect.Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new FlakyProxy(obj, flakinessFunction)); } private  FlakyProxy(Object obj, FlakinessFunction flakinessFunction); static T newJdkProxy(Object obj, FlakinessFunction flakinessFunction); }
FlakyProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj, FlakinessFunction flakinessFunction) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); return (T) java.lang.reflect.Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new FlakyProxy(obj, flakinessFunction)); } private  FlakyProxy(Object obj, FlakinessFunction flakinessFunction); static T newJdkProxy(Object obj, FlakinessFunction flakinessFunction);  }