### Question:
JaxrsClientCallback extends ClientCallback { @Override public boolean cancel(boolean mayInterruptIfRunning) { if (!started) { if (handler != null) { handler.failed(new CancellationException()); } delegate.cancel(mayInterruptIfRunning); synchronized (this) { notifyAll(); } return true; } return false; } JaxrsClientCallback(final InvocationCallback<T> handler,
                        Class<?> responseClass,
                        Type outGenericType); InvocationCallback<T> getHandler(); Type getOutGenericType(); Class<?> getResponseClass(); @Override boolean cancel(boolean mayInterruptIfRunning); Future<T> createFuture(); @SuppressWarnings("unchecked") void handleResponse(Map<String, Object> ctx, Object[] res); @Override void handleException(Map<String, Object> ctx, final Throwable ex);  }### Answer:
@Test public void testHandleCancellationCallbackWithFuture() throws Exception { final CyclicBarrier barrier = new CyclicBarrier(2); schedule(barrier, () -> future.cancel(true)); barrier.await(5, TimeUnit.SECONDS); assertThrows(InterruptedException.class, () -> future.get()); assertThrows(InterruptedException.class, () -> future.get(10, TimeUnit.MILLISECONDS)); assertThat(future.isCancelled(), equalTo(true)); assertThat(future.isDone(), equalTo(true)); assertThat(state.get(), instanceOf(InterruptedException.class)); }
@Test public void testHandleCancellationCallback() throws Exception { final CyclicBarrier barrier = new CyclicBarrier(2); schedule(barrier, () -> callback.cancel(true)); barrier.await(5, TimeUnit.SECONDS); assertThrows(InterruptedException.class, () -> callback.get()); assertThrows(InterruptedException.class, () -> callback.get(10, TimeUnit.MILLISECONDS)); assertThat(callback.isCancelled(), equalTo(true)); assertThat(callback.isDone(), equalTo(true)); assertThat(state.get(), instanceOf(CancellationException.class)); }
@Test public void testHandleCancellationCallbackWhenStarted() throws Exception { callback.start(new MessageImpl()); assertThat(future.cancel(true), equalTo(false)); assertThat(future.isCancelled(), equalTo(false)); assertThat(future.isDone(), equalTo(false)); }
@Test public void testGetResponseContextOnCancellationCallback() throws Exception { final CyclicBarrier barrier = new CyclicBarrier(1); schedule(barrier, () -> future.cancel(true)); assertThat(future.getContext(), nullValue()); assertThat(future.isCancelled(), equalTo(true)); assertThat(future.isDone(), equalTo(true)); }