@Test public void testServerLoginSuccess() { String email = "dummy@gmail.com"; String password = "password"; LoginResponse loginResponse = new LoginResponse(); doReturn(Observable.just(loginResponse)) .when(mMockDataManager) .doServerLoginApiCall(new LoginRequest .ServerLoginRequest(email, password)); mLoginPresenter.onServerLoginClick(email, password); mTestScheduler.triggerActions(); verify(mMockLoginMvpView).showLoading(); verify(mMockLoginMvpView).hideLoading(); verify(mMockLoginMvpView).openMainActivity(); }
@Override public void onServerLoginClick(String email, String password) { if (email == null || email.isEmpty()) { getMvpView().onError(R.string.empty_email); return; } if (!CommonUtils.isEmailValid(email)) { getMvpView().onError(R.string.invalid_email); return; } if (password == null || password.isEmpty()) { getMvpView().onError(R.string.empty_password); return; } getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password)) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } })); }
LoginPresenter extends BasePresenter<V> implements LoginMvpPresenter<V> { @Override public void onServerLoginClick(String email, String password) { if (email == null || email.isEmpty()) { getMvpView().onError(R.string.empty_email); return; } if (!CommonUtils.isEmailValid(email)) { getMvpView().onError(R.string.invalid_email); return; } if (password == null || password.isEmpty()) { getMvpView().onError(R.string.empty_password); return; } getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password)) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } })); } }
LoginPresenter extends BasePresenter<V> implements LoginMvpPresenter<V> { @Override public void onServerLoginClick(String email, String password) { if (email == null || email.isEmpty()) { getMvpView().onError(R.string.empty_email); return; } if (!CommonUtils.isEmailValid(email)) { getMvpView().onError(R.string.invalid_email); return; } if (password == null || password.isEmpty()) { getMvpView().onError(R.string.empty_password); return; } getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password)) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } })); } @Inject  LoginPresenter(DataManager dataManager,
                          SchedulerProvider schedulerProvider,
                          CompositeDisposable compositeDisposable); }
LoginPresenter extends BasePresenter<V> implements LoginMvpPresenter<V> { @Override public void onServerLoginClick(String email, String password) { if (email == null || email.isEmpty()) { getMvpView().onError(R.string.empty_email); return; } if (!CommonUtils.isEmailValid(email)) { getMvpView().onError(R.string.invalid_email); return; } if (password == null || password.isEmpty()) { getMvpView().onError(R.string.empty_password); return; } getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password)) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } })); } @Inject  LoginPresenter(DataManager dataManager,
                          SchedulerProvider schedulerProvider,
                          CompositeDisposable compositeDisposable); @Override void onServerLoginClick(String email, String password); @Override void onGoogleLoginClick(); @Override void onFacebookLoginClick(); }
LoginPresenter extends BasePresenter<V> implements LoginMvpPresenter<V> { @Override public void onServerLoginClick(String email, String password) { if (email == null || email.isEmpty()) { getMvpView().onError(R.string.empty_email); return; } if (!CommonUtils.isEmailValid(email)) { getMvpView().onError(R.string.invalid_email); return; } if (password == null || password.isEmpty()) { getMvpView().onError(R.string.empty_password); return; } getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password)) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } })); } @Inject  LoginPresenter(DataManager dataManager,
                          SchedulerProvider schedulerProvider,
                          CompositeDisposable compositeDisposable); @Override void onServerLoginClick(String email, String password); @Override void onGoogleLoginClick(); @Override void onFacebookLoginClick();  }