8

すべての例外が正しいことを確認しようとしています。値は でラップされているためCompletableFutures、スローExecutionExceptionされる例外は、私が通常チェックする例外が原因で発生します。簡単な例:

void foo() throws A {
  try {
    bar();
  } catch B b {
    throw new A(b);
  }
}

によってスローfoo()された例外を変換し、そのすべてがandbar()内部で行われます(コード全体はコピーしません。参考用です)。CompletableFuturesAsyncHandlers

私の単体テストではbar()、例外をスローし、呼び出し時に正しく変換されていることを確認したいと考えています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")),
        ));

Aこれまでのところは順調ですが、例外の原因が例外でありBhaving(on(A.class).getCause(), CoreMatchers.is(b))原因であることも確認したいと思いますCodeGenerationException --> StackOverflowError

TL;DR: 予想される例外の原因を取得するにはどうすればよいですか?

4

3 に答える 3