Example #1
0
 @Test
 public void setIsDoneReturnsTrueIffResponse() {
   Response response = mock(Response.class);
   assertThat(cut.isDone(), is(false));
   cut.setResponse(response);
   assertThat(cut.isDone(), is(true));
 }
Example #2
0
 @Test
 public void setIsDoneReturnsTrueIffThrowable() {
   Throwable throwable = mock(Throwable.class);
   assertThat(cut.isDone(), is(false));
   cut.setThrowable(throwable);
   assertThat(cut.isDone(), is(true));
 }
Example #3
0
 @Test
 public void setResponseLeadsToResponse()
     throws CancellationException, InterruptedException, ExecutionException {
   Response response = mock(Response.class);
   cut.setResponse(response);
   assertThat(cut.get(), is(response));
 }
Example #4
0
 @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();
 }
Example #5
0
 @Test
 public void setIsDoneReturnsFalseIfCancelled() {
   cut.setCancelled();
   assertThat(cut.isDone(), is(false));
 }
Example #6
0
 @Test
 public void isCancelledReturnsTrueIffCancelled() {
   assertThat(cut.isCancelled(), is(false));
   cut.setCancelled();
   assertThat(cut.isCancelled(), is(true));
 }
Example #7
0
 @Test(expected = CancellationException.class)
 public void setCancelledLeadsToCancelledException()
     throws CancellationException, InterruptedException, ExecutionException {
   cut.setCancelled();
   cut.get();
 }
Example #8
0
 @Test
 public void cancelReturnsFalse() {
   assertThat(cut.cancel(true), is(false));
   assertThat(cut.cancel(false), is(false));
 }