ExceptionHandlerTest.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:trading4j 作者:
/**
 * When any {@link RuntimeException} occurs, the connection should be closed, the developer should be notified on
 * this error and the admin should be warned.
 * 
 * @throws Exception
 *             Not expected to leave the method.
 */
@Test
public void whenARuntimeExceptionOccurredTheConnectionShouldBeClosedAndTheDeveloperBeWarned() throws Exception {
    final RuntimeException exampleRuntimeException = new RuntimeException(
            "The answer to everything could not be found.");
    cut.handleException(exampleRuntimeException);

    final ArgumentCaptor<Throwable> cause = ArgumentCaptor.forClass(Throwable.class);

    final ArgumentCaptor<String> developerMessage = ArgumentCaptor.forClass(String.class);
    verify(developer).unrecoverableProgrammingError(developerMessage.capture(), cause.capture());
    assertThat(developerMessage.getValue()).contains("runtime").contains("exception").contains("unhandled");
    assertThat(cause.getValue()).isSameAs(exampleRuntimeException);

    final ArgumentCaptor<String> adminMessage = ArgumentCaptor.forClass(String.class);
    verify(admin).unexpectedEvent(adminMessage.capture());
    assertThat(adminMessage.getValue()).contains("internal").contains("server").contains("client")
            .contains("connection").containsIgnoringCase("closing");

    verify(client).close();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号