FutureCollectors.java

1
package com.pivovarit.collectors;
2
3
import java.util.List;
4
import java.util.concurrent.CompletableFuture;
5
import java.util.stream.Collector;
6
import java.util.stream.Collectors;
7
8
import static java.util.stream.Collectors.toList;
9
10
/**
11
 * @author Grzegorz Piwowarek
12
 */
13
final class FutureCollectors {
14
    static <T, R> Collector<CompletableFuture<T>, ?, CompletableFuture<R>> toFuture(Collector<T, ?, R> collector) {
15 1 1. toFuture : replaced return value with null for com/pivovarit/collectors/FutureCollectors::toFuture → KILLED
        return Collectors.collectingAndThen(toList(), list -> {
16
            CompletableFuture<R> future = CompletableFuture
17
              .allOf(list.toArray(new CompletableFuture[0]))
18 1 1. lambda$null$0 : replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$null$0 → KILLED
              .thenApply(__ -> list.stream()
19
                .map(CompletableFuture::join)
20
                .collect(collector));
21
22
            // CompletableFuture#allOf doesn't shortcircuit on exception so that requires manual handling
23
            for (CompletableFuture<T> f : list) {
24
                f.whenComplete((t, throwable) -> {
25 1 1. lambda$null$1 : negated conditional → KILLED
                    if (throwable != null) {
26
                        future.completeExceptionally(throwable);
27
                    }
28
                });
29
            }
30
31 1 1. lambda$toFuture$2 : replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$toFuture$2 → KILLED
            return future;
32
        });
33
    }
34
35
    static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> toFuture() {
36 1 1. toFuture : replaced return value with null for com/pivovarit/collectors/FutureCollectors::toFuture → KILLED
        return toFuture(toList());
37
    }
38
}

Mutations

15

1.1
Location : toFuture
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldCollect()]
replaced return value with null for com/pivovarit/collectors/FutureCollectors::toFuture → KILLED

18

1.1
Location : lambda$null$0
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldCollect()]
replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$null$0 → KILLED

25

1.1
Location : lambda$null$1
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldShortcircuit()]
negated conditional → KILLED

31

1.1
Location : lambda$toFuture$2
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldCollect()]
replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$toFuture$2 → KILLED

36

1.1
Location : toFuture
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldCollect()]
replaced return value with null for com/pivovarit/collectors/FutureCollectors::toFuture → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.8