ExecutorService threadPool = Executors.newCachedThreadPool();
Future<MethodResult> blockingFuture = threadPool.submit(new MethodCallable(blockingCall));
Future<MethodResult> normalFuture = threadPool.submit(new MethodCallable(normalCall));
MethodResult normalResult = normalFuture.get();
verify(serviceMock).getAnswer();
/* getAnswer-call is finished */
assertThat((Integer) normalResult.getArg(), is(42));
try {
blockingFuture.get(200, TimeUnit.MILLISECONDS);
fail("blocking method returned premature");
} catch (TimeoutException e) {
// ignore, this is expceted
}
sync.release();
MethodResult blockingResult = blockingFuture.get();
assertThat((Long) blockingResult.getArg(), is(42L));
}