### Question:
Future implements java.util.concurrent.Future<T> { private T get(int msecs) throws ExecutionException, TimeoutException { try { return Objects.uncheckedCast(qiFutureCallGet(_fut, msecs)); } catch (Exception exception) { Throwable throwable = exception; while (throwable != null) { if (throwable instanceof CancellationException) { throw (CancellationException) throwable; } if (throwable instanceof TimeoutException) { throw (TimeoutException) throwable; } if (throwable instanceof QiException) { throwable = NativeTools.obtainRealException((QiException) throwable); if (throwable instanceof QiException) { throw (QiException) throwable; } continue; } throwable = throwable.getCause(); } Exception newException = NativeTools.obtainRealException(exception); throw new ExecutionException(newException.getMessage(), newException); } } Future(final long pFuture); static Future<T> of(final T value); static Future<T> cancelled(); static Future<T> fromError(String errorMessage); void sync(long timeout, TimeUnit unit); void sync(); void connect(Callback<T> callback, FutureCallbackType futureCallbackType); void connect(final Callback<T> callback); @Override boolean cancel(boolean mayInterruptIfRunning); synchronized void requestCancellation(); @Deprecated synchronized boolean cancel(); @Override T get(); @Override T get(long timeout, TimeUnit unit); T getValue(); ExecutionException getError(); boolean hasError(); String getErrorMessage(); @Override synchronized boolean isCancelled(); @Override synchronized boolean isDone(); synchronized boolean isSuccess(); Future<R> thenApply(final Function<Future<T>, R> function); Future<Void> thenConsume(final Consumer<Future<T>> consumer); Future<R> thenCompose(final Function<Future<T>, Future<R>> function); Future<R> andThenApply(final Function<T, R> function); Future<Void> andThenConsume(final Consumer<T> consumer); Future<R> andThenCompose(final Function<T, Future<R>> function); static Future<Void> waitAll(final Future<?>... futures); Future<T> waitFor(final Future<?>... futures);  }### Answer:
@Test public void testGetTimeout() { System.out.println("testGetTimeout..."); Future<String> fut = null; try { fut = proxy.call("longReply", "plaf"); } catch (DynamicCallException e) { System.out.println("Error calling answer function : " + e.getMessage()); return; } boolean hasTimeout = false; try { fut.get(200, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { hasTimeout = true; } catch (Exception e) { } assertTrue("Future.get() must timeout", hasTimeout); try { String ret = fut.get(); assertEquals("plafbim !", ret); } catch (Exception e1) { fail("InterruptedException must not be thrown"); } }
@Test public void testGetTimeoutSuccess() { System.out.println("testGetTimeoutSuccess..."); Future<String> fut = null; try { fut = proxy.call("longReply", "plaf"); } catch (DynamicCallException e) { System.out.println("Error calling answer function : " + e.getMessage()); return; } String ret = null; try { ret = fut.get(3, TimeUnit.SECONDS); System.out.println("Got ret"); } catch (TimeoutException e) { fail("Call must not timeout"); } catch (Exception e1) { fail("InterruptedException must not be thrown"); } assertEquals("plafbim !", ret); }
@Test public void testAdvertisedFutureReturn() throws ExecutionException, InterruptedException { Future f = proxy.call(Future.class, "getFuture", "toto"); assertEquals("ENDtoto", f.get()); }
@Test(expected = TimeoutException.class) public void testReturnedFutureIsNotFinished() throws ExecutionException, TimeoutException { Future f = proxy.call(Future.class, "getCancellableInfiniteFuture"); f.get(100, TimeUnit.MILLISECONDS); }