Search in sources :

Example 56 with Account

use of android.accounts.Account in project robolectric by robolectric.

the class ShadowAccountManagerTest method getAccountsByTypeForPackage.

@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void getAccountsByTypeForPackage() {
    Account[] accountsByTypeForPackage = am.getAccountsByTypeForPackage(null, "org.somepackage");
    assertThat(accountsByTypeForPackage).isEmpty();
    Account accountVisibleToPackage = new Account("user@gmail.com", "gmail.com");
    shadowOf(am).addAccount(accountVisibleToPackage, "org.somepackage");
    accountsByTypeForPackage = am.getAccountsByTypeForPackage("other_type", "org.somepackage");
    assertThat(accountsByTypeForPackage).isEmpty();
    accountsByTypeForPackage = am.getAccountsByTypeForPackage("gmail.com", "org.somepackage");
    assertThat(accountsByTypeForPackage).containsOnly(accountVisibleToPackage);
    accountsByTypeForPackage = am.getAccountsByTypeForPackage(null, "org.somepackage");
    assertThat(accountsByTypeForPackage).containsOnly(accountVisibleToPackage);
}
Also used : Account(android.accounts.Account) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 57 with Account

use of android.accounts.Account in project robolectric by robolectric.

the class ShadowAccountManagerTest method testAddAccountExplicitly_withPassword.

@Test
public void testAddAccountExplicitly_withPassword() {
    Account account = new Account("name", "type");
    boolean accountAdded = am.addAccountExplicitly(account, "passwd", null);
    assertThat(accountAdded).isTrue();
    assertThat(am.getPassword(account)).isEqualTo("passwd");
}
Also used : Account(android.accounts.Account) Test(org.junit.Test)

Example 58 with Account

use of android.accounts.Account in project robolectric by robolectric.

the class ShadowAccountManagerTest method invalidateAuthToken_multipleTokens.

@Test
public void invalidateAuthToken_multipleTokens() {
    Account account = new Account("name", "type1");
    shadowOf(am).addAccount(account);
    am.setAuthToken(account, "token_type_1", "token1");
    am.setAuthToken(account, "token_type_2", "token2");
    assertThat(am.peekAuthToken(account, "token_type_1")).isEqualTo("token1");
    assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2");
    // invalidate token1
    am.invalidateAuthToken("type1", "token1");
    assertThat(am.peekAuthToken(account, "token_type_1")).isNull();
    assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2");
    // invalidate token2
    am.invalidateAuthToken("type1", "token2");
    assertThat(am.peekAuthToken(account, "token_type_1")).isNull();
    assertThat(am.peekAuthToken(account, "token_type_2")).isNull();
}
Also used : Account(android.accounts.Account) Test(org.junit.Test)

Example 59 with Account

use of android.accounts.Account in project robolectric by robolectric.

the class ShadowAccountManagerTest method getAuthToken.

@Test
public void getAuthToken() throws Exception {
    Account account = new Account("name", "google.com");
    shadowOf(am).addAccount(account);
    shadowOf(am).addAuthenticator("google.com");
    am.setAuthToken(account, "auth_token_type", "token1");
    TestAccountManagerCallback<Bundle> callback = new TestAccountManagerCallback<>();
    AccountManagerFuture<Bundle> future = am.getAuthToken(account, "auth_token_type", new Bundle(), activity, callback, new Handler());
    assertThat(future.isDone()).isTrue();
    assertThat(future.getResult().getString(AccountManager.KEY_ACCOUNT_NAME)).isEqualTo(account.name);
    assertThat(future.getResult().getString(AccountManager.KEY_ACCOUNT_TYPE)).isEqualTo(account.type);
    assertThat(future.getResult().getString(AccountManager.KEY_AUTHTOKEN)).isEqualTo("token1");
    assertThat(callback.hasBeenCalled()).isTrue();
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) Handler(android.os.Handler) Test(org.junit.Test)

Example 60 with Account

use of android.accounts.Account in project robolectric by robolectric.

the class ShadowAccountManagerTest method removeAccount_throwsIllegalArgumentException_whenPassedNullAccount.

@Test
public void removeAccount_throwsIllegalArgumentException_whenPassedNullAccount() {
    Account account = new Account("name", "type");
    shadowOf(am).addAccount(account);
    try {
        am.removeAccount(null, null, null);
        fail("removeAccount() should throw an illegal argument exception if the account is null");
    } catch (IllegalArgumentException iae) {
    // Expected
    }
}
Also used : Account(android.accounts.Account) Test(org.junit.Test)

Aggregations

Account (android.accounts.Account)550 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)79 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)49 Intent (android.content.Intent)40 File (java.io.File)37 Cursor (android.database.Cursor)31 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)29 PersistableBundle (android.os.PersistableBundle)27 UserInfo (android.content.pm.UserInfo)22 MockContentResolver (android.test.mock.MockContentResolver)22 HashMap (java.util.HashMap)20 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 RemoteException (android.os.RemoteException)19 FileOutputStream (java.io.FileOutputStream)19 IOException (java.io.IOException)19 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 HashSet (java.util.HashSet)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16