Search in sources :

Example 71 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 72 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)

Example 73 with Account

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

the class ShadowAccountManagerTest method removeAccount_does.

@Test
public void removeAccount_does() throws Exception {
    Account account = new Account("name", "type");
    shadowOf(am).addAccount(account);
    TestAccountManagerCallback<Boolean> testAccountManagerCallback = new TestAccountManagerCallback<>();
    AccountManagerFuture<Boolean> future = am.removeAccount(account, testAccountManagerCallback, null);
    assertThat(future.getResult()).isTrue();
    assertThat(am.getAccountsByType("type")).isEmpty();
    assertThat(testAccountManagerCallback.accountManagerFuture).isNotNull();
}
Also used : Account(android.accounts.Account) Test(org.junit.Test)

Example 74 with Account

use of android.accounts.Account in project mobile-android by photo.

the class AccountTroveboxApiTest method getAccountNames.

private String[] getAccountNames() {
    AccountManager mAccountManager = AccountManager.get(getApplication());
    Account[] accounts = mAccountManager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    String[] names = new String[accounts.length];
    for (int i = 0; i < names.length; i++) {
        names[i] = accounts[i].name;
    }
    return names;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 75 with Account

use of android.accounts.Account in project httpclient by pixmob.

the class GoogleAppEngineAuthTask method doRun.

@Override
protected void doRun() throws Exception {
    final AccountManager am = (AccountManager) getContext().getSystemService(Context.ACCOUNT_SERVICE);
    final Account[] accounts = am.getAccountsByType(GoogleAppEngineAuthenticator.GOOGLE_ACCOUNT_TYPE);
    if (accounts == null || accounts.length == 0) {
        throw new IllegalStateException("No Google account found");
    }
    final String gaeHost = "pushpushandroid.appspot.com";
    final GoogleAppEngineAuthenticator auth = new GoogleAppEngineAuthenticator(getContext(), accounts[0], gaeHost);
    final HttpClient hc = createClient();
    hc.head("https://" + gaeHost).with(auth).execute();
}
Also used : Account(android.accounts.Account) GoogleAppEngineAuthenticator(org.pixmob.httpclient.GoogleAppEngineAuthenticator) HttpClient(org.pixmob.httpclient.HttpClient) AccountManager(android.accounts.AccountManager)

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