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