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