{
Collection<Class<?>> classes = new ArrayList<Class<?>>(Arrays.asList(Callable.class));
TestListener tl = new TestListener();
TestCallable tc = new TestCallable();
Callable o = (Callable) InterfaceProxyGenerator.getProxyInstance(testBundle,
null, classes, tc, tl);
assertCalled(tl, false, false, false);
assertNull(null, o.call());
assertCalled(tl, true, true, false);
assertEquals(Callable.class.getMethod("call"),
tl.getLastMethod());
tl.clear();
assertCalled(tl, false, false, false);
tc.setReturn(new Callable<Object>() {
public Object call() throws Exception {
throw new RuntimeException();
}
});
try {
o.call();
fail("Should throw an exception");
} catch (RuntimeException re) {
assertCalled(tl, true, false, true);
assertSame(re, tl.getLastThrowable());
}
tl.clear();
assertCalled(tl, false, false, false);
tc.setReturn(new Callable<Object>() {
public Object call() throws Exception {
try {
throw new RuntimeException();
} catch (RuntimeException re) {
return new Object();
}
}
});
try {
assertNotNull(o.call());
} finally {
assertCalled(tl, true, true, false);
}
}