@Override public void onGoogleLoginClick() { getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doGoogleLoginApiCall(new LoginRequest.GoogleLoginRequest("test1", "test1")) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override
@Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); // handle the login error here if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } }));
@After public void tearDown() throws Exception { mLoginPresenter.onDetach(); }
@Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_FB, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() {
@Override public void onGoogleLoginClick() { getMvpView().showLoading(); getCompositeDisposable().add(getInteractor() .doGoogleLoginApiCall(new LoginRequest.GoogleLoginRequest("test1", "test1")) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override
@Override public void accept(LoginResponse response) throws Exception { getInteractor().updateUserInfo( response.getAccessToken(), response.getUserId(), AppConstants.LoggedInMode.LOGGED_IN_MODE_FB, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() {
@Before public void setUp() throws Exception { CompositeDisposable compositeDisposable = new CompositeDisposable(); mTestScheduler = new TestScheduler(); TestSchedulerProvider testSchedulerProvider = new TestSchedulerProvider(mTestScheduler); mLoginPresenter = new LoginPresenter<>( mMockDataManager, testSchedulerProvider, compositeDisposable); mLoginPresenter.onAttach(mMockLoginMvpView); }
@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 onFacebookLoginClick() { getMvpView().showLoading(); getCompositeDisposable().add(getInteractor() .doFacebookLoginApiCall(new LoginRequest.FacebookLoginRequest("test3", "test4")) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override
@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(LoginResponse response) throws Exception { getInteractor().updateUserInfo( response.getAccessToken(), response.getUserId(), AppConstants.LoggedInMode.LOGGED_IN_MODE_GOOGLE, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() {
@Before public void setUp() throws Exception { CompositeDisposable compositeDisposable = new CompositeDisposable(); mTestScheduler = new TestScheduler(); TestSchedulerProvider testSchedulerProvider = new TestSchedulerProvider(mTestScheduler); mLoginPresenter = new LoginPresenter<>( mMockLoginMvpInteractor, testSchedulerProvider, compositeDisposable); mLoginPresenter.onAttach(mMockLoginMvpView); }
@Test public void testServerLoginSuccess() { String email = "dummy@gmail.com"; String password = "password"; LoginResponse loginResponse = new LoginResponse(); doReturn(Observable.just(loginResponse)) .when(mMockLoginMvpInteractor) .doServerLoginApiCall(new LoginRequest .ServerLoginRequest(email, password)); mLoginPresenter.onServerLoginClick(email, password); mTestScheduler.triggerActions(); verify(mMockLoginMvpView).showLoading(); verify(mMockLoginMvpView).hideLoading(); verify(mMockLoginMvpView).openMainActivity(); }
@Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); // handle the login error here if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } }));
@Override public void onFacebookLoginClick() { getMvpView().showLoading(); getCompositeDisposable().add(getDataManager() .doFacebookLoginApiCall(new LoginRequest.FacebookLoginRequest("test3", "test4")) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override
getMvpView().onError(R.string.empty_email); return; getMvpView().onError(R.string.invalid_email); return; getMvpView().onError(R.string.empty_password); return; getMvpView().showLoading(); getCompositeDisposable().add(getInteractor() .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password)) .subscribeOn(getSchedulerProvider().io()) .observeOn(getSchedulerProvider().ui()) .subscribe(new Consumer<LoginResponse>() { @Override
@Override public void accept(LoginResponse response) throws Exception { getDataManager().updateUserInfo( response.getAccessToken(), response.getUserId(), DataManager.LoggedInMode.LOGGED_IN_MODE_GOOGLE, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() {
@Override public void accept(LoginResponse response) throws Exception { getInteractor().updateUserInfo( response.getAccessToken(), response.getUserId(), AppConstants.LoggedInMode.LOGGED_IN_MODE_SERVER, response.getUserName(), response.getUserEmail(), response.getGoogleProfilePicUrl()); if (!isViewAttached()) { return; } getMvpView().hideLoading(); getMvpView().openMainActivity(); } }, new Consumer<Throwable>() {
@After public void tearDown() throws Exception { mLoginPresenter.onDetach(); } }
@Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideLoading(); // handle the login error here if (throwable instanceof ANError) { ANError anError = (ANError) throwable; handleApiError(anError); } } }));