mercredi 24 juillet 2019

CompletableFuture Extract from CompletionException

This test fails because I get CompletionException exception but the method throws IllegalArgumentException. So the actual exception wrapped into CompletionException. How can I extract the exception that is wrapped into CompletionException? I tried exceptionally, handle etc but does not give me what I want. I get the exception as java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: some message.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "some message")
public void someTest() {
    CompletableFuture.runAsync(() -> someMethodThrowsException()).join();
}

Aucun commentaire:

Enregistrer un commentaire