@Test
public void testAllOf() throws Throwable {

    TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION);
    int count = 10;
    List<DeferredResult<Integer>> deferredResults = IntStream.range(0, count)
            .mapToObj(ignore -> new DeferredResult<Integer>())
            .collect(Collectors.toList());
    DeferredResult<List<Integer>> deferredResult = DeferredResult.allOf(deferredResults);
    deferredResult.whenComplete(ctx.getCompletionDeferred());
    IntStream.range(0, count).forEach(i -> {
        runAfter((long) (Math.random() * 100), () -> deferredResults.get(i).complete(i));
    });
    ctx.await();
    List<Integer> result = deferredResult.getNow(exceptionSupplier());
    IntStream.range(0, count).forEach(i -> {
        Assert.assertEquals(i, result.get(i).intValue());
    });
}