MainPresenter extends BasePresenter<MainMvpView> { public void getAccountData() { checkViewAttached(); getMvpView().showProgress(true); mCompositeSubscription.add(mDataManager.getAccountDetails() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new SingleSubscriber<DataManager.AccountData>() { @Override public void onSuccess(DataManager.AccountData accountData) { getMvpView().showProgress(false); if (accountData.transactions != null && !accountData.transactions.isEmpty()) { getMvpView().showTransactions(accountData.transactions); } else { getMvpView().showEmptyTransactions(); } getMvpView().showBalance(accountData.balance); } @Override public void onError(Throwable error) { getMvpView().showProgress(false); getMvpView().showAccountError(); error.printStackTrace(); Timber.e("There was an error retrieving the account data..."); } })); } @Inject  MainPresenter(DataManager dataManager, RxEventBus rxEventBus); @Override void attachView(MainMvpView mvpView); @Override void detachView(); void getAccountData(); void signOut();  }
@Test public void getAccountDataSucceedsAndShowsAccountData() { DataManager.AccountData accountData = new DataManager.AccountData( TestDataFactory.makeBalance(), TestDataFactory.makeTransactions(5) ); stubDataManagerGetAccountDetails(Single.just(accountData)); mMainPresenter.getAccountData(); verify(mMockMainMvpView).showProgress(true); verify(mMockMainMvpView).showBalance(accountData.balance); verify(mMockMainMvpView).showTransactions(accountData.transactions); verify(mMockMainMvpView).showProgress(false); }
@Test public void getAccountDataWithEmptyTransactionsShowsNoTransactionsMessage() { DataManager.AccountData accountData = new DataManager.AccountData( TestDataFactory.makeBalance(), Collections.<Transaction>emptyList() ); stubDataManagerGetAccountDetails(Single.just(accountData)); mMainPresenter.getAccountData(); verify(mMockMainMvpView).showProgress(true); verify(mMockMainMvpView).showBalance(accountData.balance); verify(mMockMainMvpView).showEmptyTransactions(); verify(mMockMainMvpView).showProgress(false); }
@Test public void getAccountDataFailsAndShowsErrorMessage() { stubDataManagerGetAccountDetails(Single.<DataManager.AccountData>error(new RuntimeException())); mMainPresenter.getAccountData(); verify(mMockMainMvpView).showProgress(true); verify(mMockMainMvpView).showAccountError(); verify(mMockMainMvpView, never()).showEmptyTransactions(); verify(mMockMainMvpView, never()).showBalance(any(Balance.class)); verify(mMockMainMvpView, never()).showTransactions(anyListOf(Transaction.class)); verify(mMockMainMvpView).showProgress(false); }