Skip to content

Commit e5ac4c4

Browse files
committed
Added CompletableFuture.supplyAsync mock implementation
1 parent fe0c3e6 commit e5ac4c4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

utbot-framework/src/main/java/org/utbot/engine/overrides/threads/CompletableFuture.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.utbot.api.annotation.UtClassMock;
44

55
import java.util.concurrent.Executor;
6+
import java.util.function.Supplier;
67

78
@UtClassMock(target = java.util.concurrent.CompletableFuture.class, internalUsage = true)
89
public class CompletableFuture {
@@ -16,4 +17,14 @@ public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable run
1617
public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable, Executor ignoredExecutor) {
1718
return runAsync(runnable);
1819
}
20+
21+
public static <U> java.util.concurrent.CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
22+
try {
23+
final U value = supplier.get();
24+
25+
return new UtCompletableFuture<>(value).toCompletableFuture();
26+
} catch (Throwable e) {
27+
return new UtCompletableFuture<U>(e).toCompletableFuture();
28+
}
29+
}
1930
}

utbot-sample/src/main/java/org/utbot/examples/threads/FutureExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void throwingRunnableExample() throws ExecutionException, InterruptedExce
1414
future.get();
1515
}
1616

17-
public int resultFromGet() throws ExecutionException, InterruptedException {
17+
public int resultFromGet() throws ExecutionException, InterruptedException {
1818
final CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> 42);
1919

2020
return future.get();

0 commit comments

Comments
 (0)