Search in sources :

Example 96 with Account

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

the class ShadowAccountManagerTest method testGetSetUserData_addToInitiallyEmptyExtras.

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

Example 97 with Account

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

the class ShadowAccountManagerTest method getHasFeatures_returnsFalseWhenAllFeaturesNotSatisfied.

@Test
public void getHasFeatures_returnsFalseWhenAllFeaturesNotSatisfied() throws Exception {
    Account account = new Account("name", "google.com");
    shadowOf(am).addAccount(account);
    shadowOf(am).setFeatures(account, new String[] { "FEATURE_1" });
    TestAccountManagerCallback<Boolean> callback = new TestAccountManagerCallback<>();
    AccountManagerFuture<Boolean> future = am.hasFeatures(account, new String[] { "FEATURE_1", "FEATURE_2" }, callback, new Handler());
    assertThat(future.isDone()).isTrue();
    assertThat(future.getResult().booleanValue()).isEqualTo(false);
    assertThat(callback.hasBeenCalled()).isTrue();
}
Also used : Account(android.accounts.Account) Handler(android.os.Handler) Test(org.junit.Test)

Example 98 with Account

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

the class ShadowAccountManagerTest method invalidateAuthToken_multipleTokenTypesSameToken.

@Test
public void invalidateAuthToken_multipleTokenTypesSameToken() {
    Account account = new Account("name", "type1");
    shadowOf(am).addAccount(account);
    am.setAuthToken(account, "token_type_1", "token1");
    am.setAuthToken(account, "token_type_2", "token1");
    assertThat(am.peekAuthToken(account, "token_type_1")).isEqualTo("token1");
    assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token1");
    // invalidate token1
    am.invalidateAuthToken("type1", "token1");
    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 99 with Account

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

the class ShadowAccountManagerTest method testGetAccountsByType.

@Test
public void testGetAccountsByType() {
    assertThat(am.getAccountsByType("name_a")).isNotNull();
    assertThat(am.getAccounts().length).isEqualTo(0);
    Account a1 = new Account("name_a", "type_a");
    shadowOf(am).addAccount(a1);
    Account[] accounts = am.getAccountsByType("type_a");
    assertThat(accounts).isNotNull();
    assertThat(accounts.length).isEqualTo(1);
    assertThat(accounts[0]).isSameAs(a1);
    Account a2 = new Account("name_b", "type_b");
    shadowOf(am).addAccount(a2);
    accounts = am.getAccountsByType("type_a");
    assertThat(accounts).isNotNull();
    assertThat(accounts.length).isEqualTo(1);
    assertThat(accounts[0]).isSameAs(a1);
    Account a3 = new Account("name_c", "type_a");
    shadowOf(am).addAccount(a3);
    accounts = am.getAccountsByType("type_a");
    assertThat(accounts).isNotNull();
    assertThat(accounts.length).isEqualTo(2);
    assertThat(accounts[0]).isSameAs(a1);
    assertThat(accounts[1]).isSameAs(a3);
}
Also used : Account(android.accounts.Account) Test(org.junit.Test)

Example 100 with Account

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

the class ShadowAccountManagerTest method addAccount_shouldCallCallback.

@Test
public void addAccount_shouldCallCallback() throws Exception {
    shadowOf(am).addAuthenticator("google.com");
    TestAccountManagerCallback<Bundle> callback = new TestAccountManagerCallback<>();
    AccountManagerFuture<Bundle> result = am.addAccount("google.com", "auth_token_type", null, null, activity, callback, new Handler());
    assertThat(callback.hasBeenCalled()).isFalse();
    assertThat(result.isDone()).isFalse();
    shadowOf(am).addAccount(new Account("thebomb@google.com", "google.com"));
    assertThat(result.isDone()).isTrue();
    assertThat(callback.accountManagerFuture).isNotNull();
    Bundle resultBundle = callback.getResult();
    assertThat(resultBundle.getString(AccountManager.KEY_ACCOUNT_TYPE)).isEqualTo("google.com");
    assertThat(resultBundle.getString(AccountManager.KEY_ACCOUNT_NAME)).isEqualTo("thebomb@google.com");
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) Handler(android.os.Handler) Test(org.junit.Test)

Aggregations

Account (android.accounts.Account)548 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)78 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