BasicFuture implements Future<T>, Cancellable { public boolean completed(final T result) { synchronized(this) { if (this.completed) { return false; } this.completed = true; this.result = result; notifyAll(); } if (this.callback != null) { this.callback.completed(result); } return true; } BasicFuture(final FutureCallback<T> callback); @Override boolean isCancelled(); @Override boolean isDone(); @Override synchronized T get(); @Override synchronized T get(final long timeout, final TimeUnit unit); boolean completed(final T result); boolean failed(final Exception exception); @Override boolean cancel(final boolean mayInterruptIfRunning); @Override boolean cancel();  }
@Test public void testCompleted() throws Exception { final BasicFutureCallback<Object> callback = new BasicFutureCallback<>(); final BasicFuture<Object> future = new BasicFuture<>(callback); Assert.assertFalse(future.isDone()); final Object result = new Object(); final Exception boom = new Exception(); future.completed(result); future.failed(boom); Assert.assertTrue(callback.isCompleted()); Assert.assertSame(result, callback.getResult()); Assert.assertFalse(callback.isFailed()); Assert.assertNull(callback.getException()); Assert.assertFalse(callback.isCancelled()); Assert.assertSame(result, future.get()); Assert.assertTrue(future.isDone()); Assert.assertFalse(future.isCancelled()); }