@Test
public void testOnSuccessTask() {

  Continuation<Integer, Task<Integer>> continuation = new Continuation<Integer, Task<Integer>>() {
    public Task<Integer> then(Task<Integer> task) {
      return Task.forResult(task.getResult() + 1);
    }
  };
  Task<Integer> complete = Task.forResult(5).onSuccessTask(continuation);
  Task<Integer> error = Task.<Integer> forError(new IllegalStateException()).onSuccessTask(
      continuation);
  Task<Integer> cancelled = Task.<Integer> cancelled().onSuccessTask(continuation);
  assertTrue(complete.isCompleted());
  assertEquals(6, complete.getResult().intValue());
  assertFalse(complete.isFaulted());
  assertFalse(complete.isCancelled());
  assertTrue(error.isCompleted());
  assertTrue(error.getError() instanceof RuntimeException);
  assertTrue(error.isFaulted());
  assertFalse(error.isCancelled());
  assertTrue(cancelled.isCompleted());
  assertFalse(cancelled.isFaulted());
  assertTrue(cancelled.isCancelled());
}