Reputation: 21
CompletableFuture.supplyAsync(() -> { }
CompletableFuture.supplyAsync(() -> {
// line 1
// line 3
..
..
..
// line 10
}
Upvotes: 2
Views: 603
Reputation: 32028
Without the awareness of the actual test case. What you can possibly do to improve the code is to abstract those 10 lines of code to a method with can be then be called from the supplier.
This would give you an ease of testing the method separately without even calling the CompletableFuture.supplyAsync(...)
line as used in the code.
For example, consider this abstraction
CompletableFuture.supplyAsync(() -> supplyingMyValue());
where the supplyingMyValue
method exists such as
Value supplyingMyValue() {
// perform some logic
return new Value();
}
and now you can test this method independently.
Note: The solution hereby would still not test the supplyAsync
capability, but provide a way to test only the code invoked.
Upvotes: 2