ErrorHandler { public void notifyException(Exception exception, OnErrorCallback useCaseErrorCallback) { final Error error = createError(exception); notifyError(error, useCaseErrorCallback); } @Inject  ErrorHandler();  ErrorHandler(ErrorFactory errorFactory);  ErrorHandler(CallbackScheduler callbackScheduler);  ErrorHandler(ErrorFactory errorFactory, CallbackScheduler callbackScheduler); void setErrorFactory(ErrorFactory errorFactory); void setCallbackScheduler(CallbackScheduler callbackScheduler); void notifyException(Exception exception, OnErrorCallback useCaseErrorCallback); void notifyError(Error error, OnErrorCallback useCaseErrorCallback); void registerCallback(OnErrorCallback onErrorCallback); void unregisterCallback(OnErrorCallback onErrorCallback);  }
@Test public void shouldNotifyInvocationTargetExceptionWrappingAnErrorNotHandledExceptionError() { OnErrorCallback onErrorCallback = givenAnErrorCallbackThatCapturesError(); ErrorHandler errorHandler = givenAnErrorHandlerWithOnErrorCallbacks(onErrorCallback); InvocationTargetException invocationTargetException = givenAnInvocationExceptionWrappingAnErrorNotHandledException(); errorHandler.notifyException(invocationTargetException, null); verify(onErrorCallback).onError(error); }
@Test public void shouldNotifyBothRegisteredOnErrorCallbacksIfNoneCapturesError() { OnErrorCallback firstOnErrorCallback = givenAnErrorCallbackThatDoesNotCaptureError(); OnErrorCallback secondOnErrorCallback = givenAnErrorCallbackThatDoesNotCaptureError(); ErrorHandler errorHandler = givenAnErrorHandlerWithOnErrorCallbacks(firstOnErrorCallback, secondOnErrorCallback); InvocationTargetException invocationTargetException = givenAnInvocationExceptionWrappingAnErrorNotHandledException(); errorHandler.notifyException(invocationTargetException, null); verify(secondOnErrorCallback).onError(error); }
@Test public void shouldNotNotifySecondRegisteredOnErrorCallbackIfFirstOneCapturesError() { OnErrorCallback firstOnErrorCallback = givenAnErrorCallbackThatCapturesError(); OnErrorCallback secondOnErrorCallback = givenAnErrorCallbackThatDoesNotCaptureError(); ErrorHandler errorHandler = givenAnErrorHandlerWithOnErrorCallbacks(firstOnErrorCallback, secondOnErrorCallback); InvocationTargetException invocationTargetException = givenAnInvocationExceptionWrappingAnErrorNotHandledException(); errorHandler.notifyException(invocationTargetException, null); verify(secondOnErrorCallback, never()).onError(error); }