Search in sources :

Example 26 with AuthenticatorException

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();
}
Also used : AuthenticatorException(android.accounts.AuthenticatorException) Test(org.junit.Test)

Example 27 with AuthenticatorException

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");
}
Also used : Account(android.accounts.Account) AccountManagerCallback(android.accounts.AccountManagerCallback) Bundle(android.os.Bundle) Handler(android.os.Handler) AuthenticatorException(android.accounts.AuthenticatorException) Test(org.junit.Test)

Example 28 with AuthenticatorException

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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) AuthenticatorException(android.accounts.AuthenticatorException) AuthenticatorException(android.accounts.AuthenticatorException)

Aggregations

AuthenticatorException (android.accounts.AuthenticatorException)28 OperationCanceledException (android.accounts.OperationCanceledException)22 IOException (java.io.IOException)22 Bundle (android.os.Bundle)15 Account (android.accounts.Account)13 Intent (android.content.Intent)7 AccountManager (android.accounts.AccountManager)6 Context (android.content.Context)5 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)5 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)4 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)4 Test (org.junit.Test)4 Gson (com.google.gson.Gson)3 User (com.nextcloud.client.account.User)3 AccountUtils (com.owncloud.android.authentication.AccountUtils)3 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)3 PushConfigurationState (com.owncloud.android.datamodel.PushConfigurationState)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 UserHandle (android.os.UserHandle)2 GoogleHeaders (com.google.api.client.googleapis.GoogleHeaders)2