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);
}
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");
}
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();
}
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;
}
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();
}
Aggregations