PushToRemotePresenter implements PushToRemoteView.ActionDelegate { void handleError(@NotNull Throwable throwable, Notification notification) { notification.setType(ERROR); if (throwable instanceof UnauthorizedException) { console.printError(constant.messagesNotAuthorized()); notification.setMessage(constant.messagesNotAuthorized()); return; } String errorMessage = throwable.getMessage(); if (errorMessage == null) { console.printError(constant.pushFail()); notification.setMessage(constant.pushFail()); return; } try { errorMessage = dtoFactory.createDtoFromJson(errorMessage, ServiceError.class).getMessage(); if (errorMessage.equals("Unable get private ssh key")) { console.printError(constant.messagesUnableGetSshKey()); notification.setMessage(constant.messagesUnableGetSshKey()); return; } console.printError(errorMessage); notification.setMessage(errorMessage); } catch (Exception e) { console.printError(errorMessage); notification.setMessage(errorMessage); } } @Inject  PushToRemotePresenter(DtoFactory dtoFactory,
                                 PushToRemoteView view,
                                 GitServiceClient service,
                                 GitOutputPartPresenter console,
                                 AppContext appContext,
                                 GitLocalizationConstant constant,
                                 NotificationManager notificationManager,
                                 DtoUnmarshallerFactory dtoUnmarshallerFactory,
                                 BranchSearcher branchSearcher); void showDialog(); @Override void onPushClicked(); @Override void onCancelClicked(); @Override void onLocalBranchChanged(); @Override void onRepositoryChanged();  }
@Test public void testShowDefaultMessageOnUnauthorizedException() { when(constant.messagesNotAuthorized()).thenReturn("Not authorized"); presenter.handleError(mock(UnauthorizedException.class), notification); verify(notification).setType(eq(ERROR)); verify(notification).setMessage("Not authorized"); }
@Test public void testShowDefaultMessageOnExceptionWithoutMessage() { when(constant.pushFail()).thenReturn("Push fail"); presenter.handleError(mock(Throwable.class), notification); verify(notification).setType(eq(ERROR)); verify(notification).setMessage("Push fail"); }
@Test public void testShowDefaultMessageOnException() { String errorMessage = "Error"; Exception exception = mock(Exception.class); when(exception.getMessage()).thenReturn(errorMessage); presenter.handleError(exception, notification); verify(notification).setType(eq(ERROR)); verify(notification).setMessage("Error"); }