class WelcomePresenter extends BasePresenter<WelcomeMvpView> {

    public void getAccessToken(String code) {
        checkViewAttached();
        getMvpView().showLoadingState(true);
        mSubscription = mDataManager.getAccessToken(code)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SingleSubscriber<AccessToken>() {
                    @Override
                    public void onSuccess(AccessToken accessToken) {
                        getMvpView().showLoadingState(false);
                        getMvpView().launchMainActivity();
                    }

                    @Override
                    public void onError(Throwable error) {
                        getMvpView().showLoadingState(false);
                        Timber.e(error, "There was a problem retrieving the access token");
                        getMvpView().showAccessTokenError();
                    }
                });
    }

}

class WelcomePresenterTest {

    private WelcomePresenter mWelcomePresenter;
    @Mock WelcomeMvpView mMockWelcomeMvpView;
    @Mock DataManager mMockDataManager;
    @Rule
    public final RxSchedulersOverrideRule mOverrideSchedulersRule;

    @Test
    public void getAccessTokenSucceedsAndLaunchesMainActivity() {

        AccessToken accessToken = TestDataFactory.makeAccessToken();
        stubDataManagerGetAccessToken(Single.just(accessToken));
        mWelcomePresenter.getAccessToken("code");

        verify(mMockWelcomeMvpView).showLoadingState(true);
        verify(mMockWelcomeMvpView).launchMainActivity();
        verify(mMockWelcomeMvpView).showLoadingState(false);
    }

}