()
| 269 | } |
| 270 | |
| 271 | public void testWhenAllTwoErrors() { |
| 272 | final Exception error = new RuntimeException("This task failed."); |
| 273 | |
| 274 | runTaskTest(new Callable<Task<?>>() { |
| 275 | @Override |
| 276 | public Task<?> call() throws Exception { |
| 277 | final ArrayList<Task<Void>> tasks = new ArrayList<Task<Void>>(); |
| 278 | for (int i = 0; i < 20; i++) { |
| 279 | final int number = i; |
| 280 | Task<Void> task = Task.callInBackground(new Callable<Void>() { |
| 281 | @Override |
| 282 | public Void call() throws Exception { |
| 283 | Thread.sleep((long) (Math.random() * 1000)); |
| 284 | if (number == 10 || number == 11) { |
| 285 | throw error; |
| 286 | } |
| 287 | return null; |
| 288 | } |
| 289 | }); |
| 290 | tasks.add(task); |
| 291 | } |
| 292 | return Task.whenAll(tasks).continueWith(new Continuation<Void, Void>() { |
| 293 | @Override |
| 294 | public Void then(Task<Void> task) { |
| 295 | assertTrue(task.isCompleted()); |
| 296 | assertTrue(task.isFaulted()); |
| 297 | assertFalse(task.isCancelled()); |
| 298 | |
| 299 | assertTrue(task.getError() instanceof AggregateException); |
| 300 | assertEquals(2, ((AggregateException)task.getError()).getErrors().size()); |
| 301 | assertEquals(error, ((AggregateException)task.getError()).getErrors().get(0)); |
| 302 | assertEquals(error, ((AggregateException)task.getError()).getErrors().get(1)); |
| 303 | |
| 304 | for (Task<Void> t : tasks) { |
| 305 | assertTrue(t.isCompleted()); |
| 306 | } |
| 307 | return null; |
| 308 | } |
| 309 | }); |
| 310 | } |
| 311 | }); |
| 312 | } |
| 313 | |
| 314 | public void testWhenAllCancel() { |
| 315 | runTaskTest(new Callable<Task<?>>() { |
nothing calls this directly
no test coverage detected