Test CompletableFeature.exceptionally(Ex) inside public method

37 Views Asked by At

writing test cases for following code but not able to cover exceptionally part of completable feature

CompletableFuture<Optional<A>> aFuture = CompletableFuture.supplyAsync(()->Optional.ofNullable(service.getA("As")))
.exceptionally((ex)->{
     log.error("Exception Happen Fetching from another source");
     CompletableFuture<Optional<A>> aFuture1 = CompletableFuture.supplyAsync(()->Optional.ofNullable(service.getAAsB("As")))
          .exceptionally((ex2)->{
                   log.error("Exception Happen Fetching from another source also failed");
                   return Optional.empty();
     });
    try{
         return aFuture.get();    
    } catch(Exception exa){
        throw new RuntimeException(exa)
    }
});
0

There are 0 best solutions below