use of pipelite.service.InternalErrorService in project pipelite by enasequence.
the class InternalErrorHandlerTest method test.
@Test
public void test() {
InternalErrorService internalErrorService = mock(InternalErrorService.class);
doAnswer(invocation -> {
internalErrorCnt++;
String serviceName = invocation.getArgument(0);
Exception exception = invocation.getArgument(5);
assertThat(serviceName).isEqualTo(SERVICE_NAME);
assertThat(exception).isInstanceOf(RuntimeException.class);
assertThat(exception.getMessage()).isEqualTo(ERROR_MESSAGE);
return null;
}).when(internalErrorService).saveInternalError(any(), any(), any(), any(), any(), any());
InternalErrorHandler handler = new InternalErrorHandler(internalErrorService, SERVICE_NAME, this);
// Should not throw
assertThat(handler.execute(() -> {
})).isTrue();
assertThat(internalErrorCnt).isEqualTo(0);
// Should not throw
assertThat(handler.execute(() -> {
throw new RuntimeException(ERROR_MESSAGE);
}, (ex) -> {
assertThat(ex).isInstanceOf(RuntimeException.class);
assertThat(ex.getMessage()).isEqualTo(ERROR_MESSAGE);
})).isFalse();
assertThat(internalErrorCnt).isEqualTo(1);
// Should not throw
assertThat(handler.execute(() -> {
throw new RuntimeException(ERROR_MESSAGE);
}, (ex) -> {
assertThat(ex).isInstanceOf(RuntimeException.class);
assertThat(ex.getMessage()).isEqualTo(ERROR_MESSAGE);
throw new RuntimeException(RECOVER_ERROR_MESSAGE);
})).isFalse();
assertThat(internalErrorCnt).isEqualTo(2);
}
Aggregations