I am trying to verify that all my exceptions are correct. Since the values are wrapped in CompletableFutures, the exception created is ExecutionException, and the reason is the exception that I usually checked. Quick example:
void foo() throws A {
try {
bar();
} catch B b {
throw new A(b);
}
}
So that foo()translates the exception thrown, bar()and all this is done inside CompletableFuturesand AsyncHandlers(I won’t copy all the code, this is just for reference)
In my unit tests, I throw an exception bar()and want to check if it is translated correctly when called foo():
Throwable b = B("bleh");
when(mock.bar()).thenThrow(b);
ExpectedException thrown = ExpectedException.none();
thrown.expect(ExecutionException.class);
thrown.expectCause(Matchers.allOf(
instanceOf(A.class),
having(on(A.class).getMessage(),
CoreMatchers.is("some message here")),
));
So far so good, but I also want to check that the exception Ais causing the exception Band having(on(A.class).getCause(), CoreMatchers.is(b))is causingCodeGenerationException --> StackOverflowError
TL DR: How can I get the reason for the expected exception?