@Test public void oauthCallback_onSuccessCallsView() { when(oAuthInteractor.retrieveAccessToken(any(Uri.class))).thenReturn(Completable.complete()); Uri uri = mock(Uri.class); presenter.oauthCallback(uri); verify(loginView, times(1)).onAuthSuccess(); verify(loginView, times(1)).showLoading(); verifyNoMoreInteractions(loginView); }
@Test public void startOAuth_callsViewIfNoInternet() { when(networkInteractor.hasInternetConnectionCompletable()) .thenReturn(Completable.error(new NetworkInteractor.NetworkUnavailableException())); presenter.startOAuth(); verify(networkInteractor, times(1)).hasInternetConnectionCompletable(); verify(loginView, times(1)).onErrorNoInternet(); verifyNoMoreInteractions(loginView); }
@Test public void oauthCallback_onErrorCallsView() { when(oAuthInteractor.retrieveAccessToken(any(Uri.class))) .thenReturn(Completable.error(new Throwable("Error~"))); Uri uri = mock(Uri.class); presenter.oauthCallback(uri); verify(loginView, times(1)).onErrorAccessToken(); verify(loginView, times(1)).showLoading(); verifyNoMoreInteractions(loginView); }
@Test public void startOAuth_errorReturnedToView() { when(networkInteractor.hasInternetConnectionCompletable()).thenReturn(Completable.complete()); when(oAuthInteractor.retrieveRequestToken()).thenReturn(Single.error(new Throwable("Error!"))); presenter.startOAuth(); verify(networkInteractor, times(1)).hasInternetConnectionCompletable(); verify(loginView, times(1)).onErrorRequestToken(); verify(loginView, times(1)).showLoading(); verifyNoMoreInteractions(loginView); }
@Test public void startOAuth_opensBrowserOnSuccess() { when(networkInteractor.hasInternetConnectionCompletable()).thenReturn(Completable.complete()); String OAUTH_CALLBACK = "Redirect URL"; when(oAuthInteractor.retrieveRequestToken()).thenReturn(Single.just(OAUTH_CALLBACK)); presenter.startOAuth(); verify(networkInteractor, times(1)).hasInternetConnectionCompletable(); verify(loginView, times(1)).showLoading(); verify(loginView, times(1)).openBrowser(OAUTH_CALLBACK); verifyNoMoreInteractions(loginView); }
public Completable addUnsentLocationRecord(LocationRecord locationRecord) { return Completable.create( subscribe -> { BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction(); try { mBriteDatabase.insert( LocalUnsentLocationRecordTable.NAME, LocalUnsentLocationRecordTable.toContentValues(locationRecord)); transaction.markSuccessful(); subscribe.onCompleted(); } finally { transaction.end(); } }); }
public Completable clearTables() { return Completable.create( subscribe -> { BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction(); try { Cursor cursor = mBriteDatabase.query("SELECT name FROM sqlite_master WHERE type='table'"); while (cursor.moveToNext()) { mBriteDatabase.delete(cursor.getString(cursor.getColumnIndex("name")), null); } cursor.close(); transaction.markSuccessful(); subscribe.onCompleted(); } finally { transaction.end(); } }); }