LoginPresenter extends MvpBasePresenter<LoginView> { public boolean validate(String username, String password, String url) { boolean isValid = true; if (!loginService.isUsernameValid(username)) { getView().showUserNameInvalid(); isValid = false; } if (!loginService.isUsernameValid(password)) { getView().showPasswordInvalid(); isValid = false; } if (!loginService.isUrlValid(url)) { getView().showUrlInvalid(); isValid = false; } return isValid; } @Inject  LoginPresenter(Lazy<LoginService> loginService, Lazy<SystemSettingsService> systemSettingsServiceLazy); String loadLastLoginUrl(); void doLogin(String username, String password, String url, String imei); boolean validate(String username, String password, String url); @Override void attachView(LoginView view); @Override void detachView(boolean retainInstance); static final String TAG; }
@Test public void should_show_error_when_validate_empty_password_and_password() { when(loginService.isUsernameValid("")).thenReturn(false); when(loginService.isPasswordValid("")).thenReturn(false); when(loginService.isUrlValid("http: boolean valid = loginPresenter.validate("", "", "http: assertEquals(valid, false); }
@Test public void should_show_error_when_invalid_user_format() { when(loginService.isUsernameValid("pri mero")).thenReturn(false); when(loginService.isPasswordValid("password")).thenReturn(true); when(loginService.isUrlValid("http: boolean valid = loginPresenter.validate("pri mero", "password", "http: verify(loginView).showUserNameInvalid(); assertEquals(valid, false); }