Search in sources :

Example 66 with Account

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

the class ShadowAccountManagerTest method whenSchedulerPaused_getAccountsByTypeAndFeatures.

@Test
public void whenSchedulerPaused_getAccountsByTypeAndFeatures() throws Exception {
    scheduler.pause();
    Account accountWithCorrectTypeAndFeatures = new Account("account_1", "google.com");
    shadowOf(am).addAccount(accountWithCorrectTypeAndFeatures);
    shadowOf(am).setFeatures(accountWithCorrectTypeAndFeatures, new String[] { "FEATURE_1", "FEATURE_2" });
    TestAccountManagerCallback<Account[]> callback = new TestAccountManagerCallback<>();
    AccountManagerFuture<Account[]> future = am.getAccountsByTypeAndFeatures("google.com", new String[] { "FEATURE_1", "FEATURE_2" }, callback, new Handler());
    assertThat(future.isDone()).isFalse();
    assertThat(callback.hasBeenCalled()).isFalse();
    scheduler.unPause();
    assertThat(future.getResult()).containsOnly(accountWithCorrectTypeAndFeatures);
    assertThat(future.isDone()).isTrue();
    assertThat(callback.hasBeenCalled()).isTrue();
}
Also used : Account(android.accounts.Account) Handler(android.os.Handler) Test(org.junit.Test)

Example 67 with Account

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

the class ShadowAccountManagerTest method testGetSetPassword_overwrite.

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

Example 68 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 69 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 70 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)

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