@Test public void setIsDoneReturnsTrueIffResponse() { Response response = mock(Response.class); assertThat(cut.isDone(), is(false)); cut.setResponse(response); assertThat(cut.isDone(), is(true)); }
@Test public void setIsDoneReturnsTrueIffThrowable() { Throwable throwable = mock(Throwable.class); assertThat(cut.isDone(), is(false)); cut.setThrowable(throwable); assertThat(cut.isDone(), is(true)); }
@Test public void setResponseLeadsToResponse() throws CancellationException, InterruptedException, ExecutionException { Response response = mock(Response.class); cut.setResponse(response); assertThat(cut.get(), is(response)); }
@Test public void setThrowableLeadsToThrowable() throws CancellationException, InterruptedException { Throwable throwable = mock(Throwable.class); cut.setThrowable(throwable); try { cut.get(); } catch (ExecutionException e) { assertThat(e.getCause(), is(throwable)); return; } fail(); }
@Test public void setIsDoneReturnsFalseIfCancelled() { cut.setCancelled(); assertThat(cut.isDone(), is(false)); }
@Test public void isCancelledReturnsTrueIffCancelled() { assertThat(cut.isCancelled(), is(false)); cut.setCancelled(); assertThat(cut.isCancelled(), is(true)); }
@Test(expected = CancellationException.class) public void setCancelledLeadsToCancelledException() throws CancellationException, InterruptedException, ExecutionException { cut.setCancelled(); cut.get(); }
@Test public void cancelReturnsFalse() { assertThat(cut.cancel(true), is(false)); assertThat(cut.cancel(false), is(false)); }