public String getTokenWithNotification(Context context, String accountName, String scope, Bundle extras, String authority, Bundle syncBundle) throws IOException, UserRecoverableNotifiedException, GoogleAuthException { return getTokenWithNotification(context, new Account(accountName, "robo"), scope, extras, authority, syncBundle); }
public String getTokenWithNotification(Context context, String accountName, String scope, Bundle extras, Intent callback) throws IOException, UserRecoverableNotifiedException, GoogleAuthException { return getTokenWithNotification(context, new Account(accountName, "robo"), scope, extras, callback); }
@Test public void shouldProvideEqualAndHashCode() throws Exception { assertThat(new Account("a", "b")).isEqualTo(new Account("a", "b")); assertThat(new Account("a", "b")).isNotEqualTo(new Account("c", "b")); assertThat(new Account("a", "b").hashCode()).isEqualTo(new Account("a", "b").hashCode()); assertThat(new Account("a", "b").hashCode()).isNotEqualTo(new Account("c", "b").hashCode()); } }
@Before public void setUp() { contentResolver = ApplicationProvider.getApplicationContext().getContentResolver(); shadowContentResolver = shadowOf(contentResolver); uri21 = Uri.parse(EXTERNAL_CONTENT_URI.toString() + "/21"); uri22 = Uri.parse(EXTERNAL_CONTENT_URI.toString() + "/22"); a = new Account("a", "type"); b = new Account("b", "type"); }
@Test public void testReadWriteParcelable() { Account a1 = new Account("name", "type"); parcel.writeParcelable(a1, 0); parcel.setDataPosition(0); Account a2 = parcel.readParcelable(Account.class.getClassLoader()); assertEquals(a1, a2); }
@Test @Config(minSdk = LOLLIPOP_MR1) public void removeAccountExplicitly() { assertThat(am.removeAccountExplicitly(new Account("non_existant_account@gmail.com", "gmail.com"))).isFalse(); assertThat(am.removeAccountExplicitly(null)).isFalse(); Account account = new Account("name@gmail.com", "gmail.com"); shadowOf(am).addAccount(account); assertThat(am.removeAccountExplicitly(account)).isTrue(); }
@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"); }
@Test public void removeAccount_doesNotRemoveAccountOfDifferentName() throws Exception { Account account = new Account("name", "type"); shadowOf(am).addAccount(account); Account wrongAccount = new Account("wrong_name", "type"); AccountManagerFuture<Boolean> future = am.removeAccount(wrongAccount, null, null); assertThat(future.getResult()).isFalse(); assertThat(am.getAccountsByType("type")).isNotEmpty(); }
@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"); }
@Test public void testGetSetPassword_setInAccountInitiallyWithNoPassword() { Account account = new Account("name", "type"); boolean accountAdded = am.addAccountExplicitly(account, null, null); assertThat(accountAdded).isTrue(); assertThat(am.getPassword(account)).isNull(); am.setPassword(account, "passwd"); assertThat(am.getPassword(account)).isEqualTo("passwd"); }
@Test public void testGetSetPassword_remove() { 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, null); assertThat(am.getPassword(account)).isNull(); }
@Test public void testAddAccountExplicitly_notifiesListenersIfSuccessful() { TestOnAccountsUpdateListener listener = new TestOnAccountsUpdateListener(); am.addOnAccountsUpdatedListener(listener, null, false); assertThat(listener.getInvocationCount()).isEqualTo(0); Account account = new Account("name", "type"); boolean accountAdded = am.addAccountExplicitly(account, "passwd", null); assertThat(accountAdded).isTrue(); assertThat(listener.getInvocationCount()).isEqualTo(1); }
@Test public void testGetSetUserData_overwrite() { 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"); am.setUserData(account, "key123", "value456"); assertThat(am.getUserData(account, "key123")).isEqualTo("value456"); }
@Test public void getHasFeatures_returnsTrueWhenAllFeaturesSatisfied() throws Exception { Account account = new Account("name", "google.com"); shadowOf(am).addAccount(account); shadowOf(am).setFeatures(account, new String[] { "FEATURE_1", "FEATURE_2" }); 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(true); assertThat(callback.hasBeenCalled()).isTrue(); }
@Test public void removeAccount_doesNotNotifyIfUnuccessful() { Account account = new Account("name", "type"); TestOnAccountsUpdateListener listener = new TestOnAccountsUpdateListener(); am.addOnAccountsUpdatedListener(listener, null, false); assertThat(listener.getInvocationCount()).isEqualTo(0); // The account has not been added am.removeAccount(account, null, null); assertThat(listener.getInvocationCount()).isEqualTo(0); }
@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(); }
@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 } }
@Test public void testAccountsUpdateListener_duplicate() { TestOnAccountsUpdateListener listener = new TestOnAccountsUpdateListener(); am.addOnAccountsUpdatedListener(listener, null, false); am.addOnAccountsUpdatedListener(listener, null, false); assertThat(listener.getInvocationCount()).isEqualTo(0); Account account = new Account("name", "type"); shadowOf(am).addAccount(account); assertThat(listener.getInvocationCount()).isEqualTo(1); }
@Test public void testAccountsUpdateListener_listenerNotInvokedAfterRemoval() { TestOnAccountsUpdateListener listener = new TestOnAccountsUpdateListener(); am.addOnAccountsUpdatedListener(listener, null, false); assertThat(listener.getInvocationCount()).isEqualTo(0); Account account = new Account("name", "type"); shadowOf(am).addAccount(account); assertThat(listener.getInvocationCount()).isEqualTo(1); am.removeOnAccountsUpdatedListener(listener); shadowOf(am).addAccount(account); assertThat(listener.getInvocationCount()).isEqualTo(1); }
/** * Test sorting of users that don't match login */ public void testNoLoginMatch() { Account account = new Account("m", "t"); UserComparator comparator = new UserComparator(account); assertTrue(comparator.compare(createUser("a"), createUser("c")) < 0); assertTrue(comparator.compare(createUser("db"), createUser("da")) > 0); }