RunnerAsyncRequestCallback extends AsyncRequestCallback<T> { @Override protected void onFailure(@NotNull Throwable exception) { if (failureCallback != null) { failureCallback.onFailure(exception); return; } String message = exception.getMessage(); boolean isServerExceptionMessage = !message.isEmpty() && exception instanceof ServerException; notificationManager.showError(isServerExceptionMessage ? message : locale.unknownErrorMessage()); } RunnerAsyncRequestCallback(@NotNull NotificationManager notificationManager,
                                      @NotNull RunnerLocalizationConstant locale,
                                      @Nullable Unmarshallable<T> unmarshaller,
                                      @NotNull SuccessCallback<T> successCallback,
                                      @Nullable FailureCallback failureCallback);   }
@Test public void failureCallBackShouldBeCalledWhenItIsNotNull() throws Exception { asyncRequestCallback.onFailure(exception); verify(failureCallback).onFailure(exception); verify(notificationManager, never()).showError(anyString()); }
@Test public void errorMessageShouldBeShownWhenExceptionMessageIsEmpty() throws Exception { RunnerAsyncRequestCallback<Object> asyncRequestCallback = new RunnerAsyncRequestCallback<>(notificationManager, locale, unmarshaller, successCallback, null); when(exception.getMessage()).thenReturn(""); when(locale.unknownErrorMessage()).thenReturn(SOME_TEXT); asyncRequestCallback.onFailure(exception); verify(notificationManager).showError(SOME_TEXT); verify(locale).unknownErrorMessage(); verify(failureCallback, never()).onFailure(exception); }
@Test public void errorMessageShouldBeShownWhenExceptionMessageIsNotEmpty() throws Exception { RunnerAsyncRequestCallback<Object> asyncRequestCallback = new RunnerAsyncRequestCallback<>(notificationManager, locale, unmarshaller, successCallback, null); when(exception.getMessage()).thenReturn(SOME_TEXT); asyncRequestCallback.onFailure(exception); verify(notificationManager).showError(SOME_TEXT); verify(locale, never()).unknownErrorMessage(); verify(failureCallback, never()).onFailure(exception); }