@Test
public void testContinueWhile() {

  final AtomicInteger count = new AtomicInteger(0);
  runTaskTest(new Callable<Task<?>>() {
    public Task<?> call() throws Exception {
      return Task.forResult(null).continueWhile(new Callable<Boolean>() {
        public Boolean call() throws Exception {
          return count.get() < 10;
        }
      }, new Continuation<Void, Task<Void>>() {
        public Task<Void> then(Task<Void> task) throws Exception {
          count.incrementAndGet();
          return null;
        }
      }).continueWith(new Continuation<Void, Void>() {
        public Void then(Task<Void> task) throws Exception {
          assertEquals(10, count.get());
          return null;
        }
      });
    }
  });
}