DefaultCommandFuture implements CommandFuture<V> { @Override public boolean cancel(boolean mayInterruptIfRunning) { if(isDone()){ return false; } synchronized(this){ if(isDone()){ return false; } result = CANCELLED_RESULT; if (hasWaiters()) { notifyAll(); } notifyListeners(); } return true; } DefaultCommandFuture();  DefaultCommandFuture(Command<V> command); @Override boolean cancel(boolean mayInterruptIfRunning); @Override boolean isCancelled(); @Override boolean isDone(); @Override CommandFuture<V> sync(); @Override V get(); @SuppressWarnings("unchecked") @Override V getNow(); @Override V get(long timeout, TimeUnit unit); @Override boolean isSuccess(); @Override Throwable cause(); @Override void setSuccess(); @Override void setSuccess(V result); @Override void setFailure(Throwable cause); @Override Future<V> await(); @Override boolean await(long timeout, TimeUnit unit); @Override void addListener(CommandFutureListener<V> commandFutureListener); @Override Command<V> command(); @Override String toString();  }
@Test(expected = CancellationException.class) public void testCancel() throws InterruptedException, ExecutionException{ jobFuture.await(1000, TimeUnit.MILLISECONDS); new Thread(new Runnable() { @Override public void run() { jobFuture.cancel(true); } }).start(); sleep(100); Assert.assertTrue(jobFuture.isCancelled()); jobFuture.get(); }