DataManager { public Single<AccessToken> getAccessToken(String code) { return mMondroidService.getAccessToken(null, "authorization_code", BuildConfig.CLIENT_ID, BuildConfig.CLIENT_SECRET, BuildConfig.REDIRECT_URI, code) .doOnSuccess(new Action1<AccessToken>() { @Override public void call(AccessToken accessToken) { mPreferencesHelper.putAccessToken(accessToken); } }); } @Inject  DataManager(MondroidService mondroidService, PreferencesHelper preferencesHelper); Single<AccessToken> getAccessToken(String code); Single<Boolean> isUserSignedIn(); Completable signOut(); Single<AccountsResponse> getAccounts(); Single<AccountData> getAccountDetails(); Single<Balance> getBalance(String accountId); Single<List<Transaction>> getTransactions(String accountId);  }
@Test public void getAccessTokenCompletesAndEmitsAccessToken() { AccessToken accessToken = TestDataFactory.makeAccessToken(); stubMondoServiceGetAccessToken(Single.just(accessToken)); TestSubscriber<AccessToken> testSubscriber = new TestSubscriber<>(); mDataManager.getAccessToken("code").subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertValue(accessToken); }
@Test public void getAccessTokenSavesAccessTokenInPreferences() { AccessToken accessToken = TestDataFactory.makeAccessToken(); stubMondoServiceGetAccessToken(Single.just(accessToken)); TestSubscriber<AccessToken> testSubscriber = new TestSubscriber<>(); mDataManager.getAccessToken("code").subscribe(testSubscriber); verify(mMockPreferencesHelper).putAccessToken(accessToken); }