LoginPresenter extends AbstractPresenter<ILoginView> { public void onLoginClick() { logger.debug("onLoginClick() called"); getView().showProgress(); call = loginModule.login(login, password); call.enqueue( data -> getView().advance(), error -> { if (error instanceof LoginException) { hasLoginError = true; getView().setLoginErrorVisible(true); } else if (error instanceof PasswordException) { hasPasswordError = true; getView().setPasswordErrorVisible(true); } else if (error instanceof NetworkException) { getView().notifyNetworkError(); } else { getView().notifyGenericError(); } getView().showContent(); }); } @Inject  LoginPresenter(AccountModule accountModule, LoginModule loginModule,
                          @Named(VIEW_EXECUTOR) Executor executor); @Override void onCreate(); @Override void onBind(ILoginView view); @Override void onDestroy(); void onLoginChanged(@NonNull String newLogin); void onPasswordChanged(@NonNull String newPassword); void onLoginClick(); void onRememberCheck(boolean checked);  }
@Test public void loginClickWouldShowProgress() { initPresenter(); when(loginModule.login(anyString(), anyString())).thenReturn(Call.empty()); presenter.onLoginClick(); verify(view).showProgress(); }
@Test public void loginClickWouldAdvanceOnSuccess() { initPresenter(); when(loginModule.login(anyString(), anyString())).thenReturn(Call.just(new Object())); presenter.onLoginClick(); verify(view).advance(); }
@Test public void handleLoginError() { initPresenter(); when(loginModule.login(anyString(), anyString())).thenReturn(Call.error(new LoginException())); presenter.onLoginClick(); verify(view).setLoginErrorVisible(true); }
@Test public void handlePasswordError() { initPresenter(); when(loginModule.login(anyString(), anyString())).thenReturn(Call.error(new PasswordException())); presenter.onLoginClick(); verify(view).setPasswordErrorVisible(true); }
@Test public void handleNetworkError() { initPresenter(); when(loginModule.login(anyString(), anyString())) .thenReturn(Call.error(new NetworkException())); presenter.onLoginClick(); verify(view).notifyNetworkError(); }
@Test public void handleGenericError() { initPresenter(); when(loginModule.login(anyString(), anyString())) .thenReturn(Call.error(new ServerException())); presenter.onLoginClick(); verify(view).notifyGenericError(); }