use of android.accounts.AuthenticatorException in project FastDev4Android by jiangqqlmj.
the class AndroidAuthenticatorTest method failedGetAuthToken.
@Test(expected = AuthFailureError.class)
public void failedGetAuthToken() throws Exception {
when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture);
when(mFuture.getResult()).thenThrow(new AuthenticatorException("sadness!"));
mAuthenticator.getAuthToken();
}
use of android.accounts.AuthenticatorException in project sms-backup-plus by jberkel.
the class TokenRefresherTest method shouldHandleExceptionsThrownByFuture.
@Test
public void shouldHandleExceptionsThrownByFuture() throws Exception {
when(authPreferences.getOauth2Token()).thenReturn("token");
when(authPreferences.getOauth2Username()).thenReturn("username");
AccountManagerFuture<Bundle> future = mock(AccountManagerFuture.class);
when(accountManager.getAuthToken(notNull(Account.class), anyString(), isNull(Bundle.class), anyBoolean(), any(AccountManagerCallback.class), any(Handler.class))).thenReturn(future);
AuthenticatorException exception = new AuthenticatorException();
when(future.getResult()).thenThrow(exception);
try {
refresher.refreshOAuth2Token();
fail("expected exception");
} catch (TokenRefreshException e) {
assertThat(e.getCause()).isSameAs(exception);
}
verify(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token");
}
use of android.accounts.AuthenticatorException in project WeatherApp by Cilestal.
the class CountryListInteractor method loadNetworkCityList.
private void loadNetworkCityList(DisposableObserver<List<Region>> observer, @Nullable String language) {
Disposable disposable = mRepository.getNetworkCountryList(language).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(listResponse -> {
if (listResponse.isSuccessful()) {
observer.onNext(listResponse.body());
} else if (listResponse.code() == AUTH_ERROR_CODE) {
observer.onError(new AuthenticatorException());
} else {
observer.onError(new Exception(listResponse.errorBody().string()));
}
}, observer::onError);
addDisposable(disposable);
}
Aggregations