in BoltsTest/src/bolts/TaskTest.java [230:269]
public void testWhenAllOneError() {
final Exception error = new RuntimeException("This task failed.");
runTaskTest(new Callable<Task<?>>() {
@Override
public Task<?> call() throws Exception {
final ArrayList<Task<Void>> tasks = new ArrayList<Task<Void>>();
for (int i = 0; i < 20; i++) {
final int number = i;
Task<Void> task = Task.callInBackground(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep((long) (Math.random() * 1000));
if (number == 10) {
throw error;
}
return null;
}
});
tasks.add(task);
}
return Task.whenAll(tasks).continueWith(new Continuation<Void, Void>() {
@Override
public Void then(Task<Void> task) {
assertTrue(task.isCompleted());
assertTrue(task.isFaulted());
assertFalse(task.isCancelled());
assertFalse(task.getError() instanceof AggregateException);
assertEquals(error, task.getError());
for (Task<Void> t : tasks) {
assertTrue(t.isCompleted());
}
return null;
}
});
}
});
}