use of android.accounts.Account in project robolectric by robolectric.
the class ShadowAccountManagerTest method getAccountsByTypeForPackage.
@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void getAccountsByTypeForPackage() {
Account[] accountsByTypeForPackage = am.getAccountsByTypeForPackage(null, "org.somepackage");
assertThat(accountsByTypeForPackage).isEmpty();
Account accountVisibleToPackage = new Account("user@gmail.com", "gmail.com");
shadowOf(am).addAccount(accountVisibleToPackage, "org.somepackage");
accountsByTypeForPackage = am.getAccountsByTypeForPackage("other_type", "org.somepackage");
assertThat(accountsByTypeForPackage).isEmpty();
accountsByTypeForPackage = am.getAccountsByTypeForPackage("gmail.com", "org.somepackage");
assertThat(accountsByTypeForPackage).containsOnly(accountVisibleToPackage);
accountsByTypeForPackage = am.getAccountsByTypeForPackage(null, "org.somepackage");
assertThat(accountsByTypeForPackage).containsOnly(accountVisibleToPackage);
}
use of android.accounts.Account in project robolectric by robolectric.
the class ShadowAccountManagerTest method testAddAccountExplicitly_withPassword.
@Test
public void testAddAccountExplicitly_withPassword() {
Account account = new Account("name", "type");
boolean accountAdded = am.addAccountExplicitly(account, "passwd", null);
assertThat(accountAdded).isTrue();
assertThat(am.getPassword(account)).isEqualTo("passwd");
}
use of android.accounts.Account in project robolectric by robolectric.
the class ShadowAccountManagerTest method invalidateAuthToken_multipleTokens.
@Test
public void invalidateAuthToken_multipleTokens() {
Account account = new Account("name", "type1");
shadowOf(am).addAccount(account);
am.setAuthToken(account, "token_type_1", "token1");
am.setAuthToken(account, "token_type_2", "token2");
assertThat(am.peekAuthToken(account, "token_type_1")).isEqualTo("token1");
assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2");
// invalidate token1
am.invalidateAuthToken("type1", "token1");
assertThat(am.peekAuthToken(account, "token_type_1")).isNull();
assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2");
// invalidate token2
am.invalidateAuthToken("type1", "token2");
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 getAuthToken.
@Test
public void getAuthToken() throws Exception {
Account account = new Account("name", "google.com");
shadowOf(am).addAccount(account);
shadowOf(am).addAuthenticator("google.com");
am.setAuthToken(account, "auth_token_type", "token1");
TestAccountManagerCallback<Bundle> callback = new TestAccountManagerCallback<>();
AccountManagerFuture<Bundle> future = am.getAuthToken(account, "auth_token_type", new Bundle(), activity, callback, new Handler());
assertThat(future.isDone()).isTrue();
assertThat(future.getResult().getString(AccountManager.KEY_ACCOUNT_NAME)).isEqualTo(account.name);
assertThat(future.getResult().getString(AccountManager.KEY_ACCOUNT_TYPE)).isEqualTo(account.type);
assertThat(future.getResult().getString(AccountManager.KEY_AUTHTOKEN)).isEqualTo("token1");
assertThat(callback.hasBeenCalled()).isTrue();
}
use of android.accounts.Account in project robolectric by robolectric.
the class ShadowAccountManagerTest method removeAccount_throwsIllegalArgumentException_whenPassedNullAccount.
@Test
public void removeAccount_throwsIllegalArgumentException_whenPassedNullAccount() {
Account account = new Account("name", "type");
shadowOf(am).addAccount(account);
try {
am.removeAccount(null, null, null);
fail("removeAccount() should throw an illegal argument exception if the account is null");
} catch (IllegalArgumentException iae) {
// Expected
}
}
Aggregations