Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java

Issue 22978010: [Android] Remove all usage of com.google.common.collect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nyquist fixes Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java
diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java
index db27879c47e24bbf0f000a77c758968ff882de72..18d65072464e33b0cf15776bc68b5f2772e64ac2 100644
--- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java
+++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java
@@ -11,15 +11,13 @@ import android.os.Bundle;
import android.test.ServiceTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import com.google.ipc.invalidation.external.client.InvalidationListener.RegistrationState;
import com.google.ipc.invalidation.external.client.contrib.AndroidListener;
import com.google.ipc.invalidation.external.client.types.ErrorInfo;
import com.google.ipc.invalidation.external.client.types.Invalidation;
import com.google.ipc.invalidation.external.client.types.ObjectId;
+import org.chromium.base.CollectionUtil;
import org.chromium.base.test.util.AdvancedMockContext;
import org.chromium.base.test.util.Feature;
import org.chromium.sync.internal_api.pub.base.ModelType;
@@ -27,7 +25,10 @@ import org.chromium.sync.notifier.InvalidationController.IntentProtocol;
import org.chromium.sync.notifier.InvalidationPreferences.EditContext;
import org.chromium.sync.signin.AccountManagerHelper;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -50,7 +51,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
@Override
public void setUp() throws Exception {
super.setUp();
- mStartServiceIntents = Lists.newArrayList();
+ mStartServiceIntents = new ArrayList<Intent>();
setContext(new AdvancedMockContext(getContext()) {
@Override
public ComponentName startService(Intent intent) {
@@ -78,49 +79,52 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
* Test plan: compute the set of registration operations resulting from various combinations
* of existing and desired registrations. Verifying that they are correct.
*/
- List<ObjectId> regAccumulator = Lists.newArrayList();
- List<ObjectId> unregAccumulator = Lists.newArrayList();
+ Set<ObjectId> regAccumulator = new HashSet<ObjectId>();
+ Set<ObjectId> unregAccumulator = new HashSet<ObjectId>();
// Empty existing and desired registrations should yield empty operation sets.
InvalidationService.computeRegistrationOps(
ModelType.modelTypesToObjectIds(
- Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)),
+ CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)),
ModelType.modelTypesToObjectIds(
- Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)),
+ CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)),
regAccumulator, unregAccumulator);
assertEquals(0, regAccumulator.size());
assertEquals(0, unregAccumulator.size());
// Equal existing and desired registrations should yield empty operation sets.
- InvalidationService.computeRegistrationOps(Sets.<ObjectId>newHashSet(),
- Sets.<ObjectId>newHashSet(), regAccumulator, unregAccumulator);
+ InvalidationService.computeRegistrationOps(new HashSet<ObjectId>(),
+ new HashSet<ObjectId>(), regAccumulator, unregAccumulator);
assertEquals(0, regAccumulator.size());
assertEquals(0, unregAccumulator.size());
// Empty existing and non-empty desired registrations should yield desired registrations
// as the registration operations to do and no unregistrations.
Set<ObjectId> desiredTypes =
- Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId());
+ CollectionUtil.newHashSet(
+ ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId());
InvalidationService.computeRegistrationOps(
- Sets.<ObjectId>newHashSet(),
+ new HashSet<ObjectId>(),
desiredTypes,
regAccumulator, unregAccumulator);
assertEquals(
- Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
- Sets.newHashSet(regAccumulator));
+ CollectionUtil.newHashSet(
+ ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
+ new HashSet<ObjectId>(regAccumulator));
assertEquals(0, unregAccumulator.size());
regAccumulator.clear();
// Unequal existing and desired registrations should yield both registrations and
// unregistrations. We should unregister TYPED_URL and register BOOKMARK, keeping SESSION.
InvalidationService.computeRegistrationOps(
- Sets.<ObjectId>newHashSet(
+ CollectionUtil.newHashSet(
ModelType.SESSION.toObjectId(), ModelType.TYPED_URL.toObjectId()),
- Sets.<ObjectId>newHashSet(
+ CollectionUtil.newHashSet(
ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
regAccumulator, unregAccumulator);
- assertEquals(Lists.newArrayList(ModelType.BOOKMARK.toObjectId()), regAccumulator);
- assertEquals(Lists.newArrayList(ModelType.TYPED_URL.toObjectId()), unregAccumulator);
+ assertEquals(CollectionUtil.newHashSet(ModelType.BOOKMARK.toObjectId()), regAccumulator);
+ assertEquals(CollectionUtil.newHashSet(ModelType.TYPED_URL.toObjectId()),
+ unregAccumulator);
regAccumulator.clear();
unregAccumulator.clear();
}
@@ -136,7 +140,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Persist some registrations.
InvalidationPreferences invPrefs = new InvalidationPreferences(getContext());
EditContext editContext = invPrefs.edit();
- invPrefs.setSyncTypes(editContext, Lists.newArrayList("BOOKMARK", "SESSION"));
+ invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("BOOKMARK", "SESSION"));
assertTrue(invPrefs.commit(editContext));
// Issue ready.
@@ -147,9 +151,9 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
assertTrue(Arrays.equals(otherCid, InvalidationService.getClientIdForTest()));
// Verify registrations issued.
- assertEquals(
- Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
- Sets.newHashSet(getService().mRegistrations.get(0)));
+ assertEquals(CollectionUtil.newHashSet(
+ ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
+ new HashSet<ObjectId>(getService().mRegistrations.get(0)));
}
@SmallTest
@@ -169,15 +173,15 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Persist some registrations.
InvalidationPreferences invPrefs = new InvalidationPreferences(getContext());
EditContext editContext = invPrefs.edit();
- invPrefs.setSyncTypes(editContext, Lists.newArrayList("BOOKMARK", "SESSION"));
+ invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("BOOKMARK", "SESSION"));
assertTrue(invPrefs.commit(editContext));
// Reissue registrations and verify that the appropriate registrations are issued.
getService().reissueRegistrations(CLIENT_ID);
assertEquals(1, getService().mRegistrations.size());
- assertEquals(
- Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
- Sets.newHashSet(getService().mRegistrations.get(0)));
+ assertEquals(CollectionUtil.newHashSet(
+ ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()),
+ new HashSet<ObjectId>(getService().mRegistrations.get(0)));
}
@SmallTest
@@ -195,7 +199,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Initial test setup: persist a single registration into preferences.
InvalidationPreferences invPrefs = new InvalidationPreferences(getContext());
EditContext editContext = invPrefs.edit();
- invPrefs.setSyncTypes(editContext, Lists.newArrayList("SESSION"));
+ invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("SESSION"));
assertTrue(invPrefs.commit(editContext));
// Cases 1 and 2: calls matching desired state cause no actions.
@@ -211,7 +215,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
RegistrationState.REGISTERED);
assertEquals(1, getService().mUnregistrations.size());
assertEquals(0, getService().mRegistrations.size());
- assertEquals(Lists.newArrayList(ModelType.BOOKMARK.toObjectId()),
+ assertEquals(CollectionUtil.newArrayList(ModelType.BOOKMARK.toObjectId()),
getService().mUnregistrations.get(0));
// Case 4: unregistration of a desired object triggers a registration.
@@ -219,7 +223,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
RegistrationState.UNREGISTERED);
assertEquals(1, getService().mUnregistrations.size());
assertEquals(1, getService().mRegistrations.size());
- assertEquals(Lists.newArrayList(ModelType.SESSION.toObjectId()),
+ assertEquals(CollectionUtil.newArrayList(ModelType.SESSION.toObjectId()),
getService().mRegistrations.get(0));
}
@@ -241,7 +245,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Initial test setup: persist a single registration into preferences.
InvalidationPreferences invPrefs = new InvalidationPreferences(getContext());
EditContext editContext = invPrefs.edit();
- invPrefs.setSyncTypes(editContext, Lists.newArrayList("SESSION"));
+ invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("SESSION"));
assertTrue(invPrefs.commit(editContext));
// Cases 2 and 4: permanent registration failures never cause calls to be made.
@@ -256,7 +260,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
getService().informRegistrationFailure(CLIENT_ID, ModelType.SESSION.toObjectId(), true, "");
assertEquals(1, getService().mRegistrations.size());
assertTrue(getService().mUnregistrations.isEmpty());
- assertEquals(Lists.newArrayList(ModelType.SESSION.toObjectId()),
+ assertEquals(CollectionUtil.newArrayList(ModelType.SESSION.toObjectId()),
getService().mRegistrations.get(0));
// Case 3: transient failure of an undesired registration results in unregistration.
@@ -264,7 +268,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
"");
assertEquals(1, getService().mRegistrations.size());
assertEquals(1, getService().mUnregistrations.size());
- assertEquals(Lists.newArrayList(ModelType.BOOKMARK.toObjectId()),
+ assertEquals(CollectionUtil.newArrayList(ModelType.BOOKMARK.toObjectId()),
getService().mUnregistrations.get(0));
}
@@ -484,8 +488,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
getService().onCreate();
// Send register Intent.
- ImmutableSet<ModelType> desiredRegistrations =
- ImmutableSet.of(ModelType.BOOKMARK, ModelType.SESSION);
+ Set<ModelType> desiredRegistrations = CollectionUtil.newHashSet(
+ ModelType.BOOKMARK, ModelType.SESSION);
Account account = AccountManagerHelper.createAccountFromName("test@example.com");
Intent registrationIntent = IntentProtocol.createRegisterIntent(account, false,
desiredRegistrations);
@@ -504,7 +508,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// verify that the on-disk state is updated and that no addition Intents are issued.
getService().onHandleIntent(IntentProtocol.createRegisterIntent(account, true, null));
assertEquals(account, invPrefs.getSavedSyncedAccount());
- assertEquals(ImmutableSet.of(ModelType.ALL_TYPES_TYPE), invPrefs.getSavedSyncedTypes());
+ assertEquals(CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE),
+ invPrefs.getSavedSyncedTypes());
assertEquals(1, mStartServiceIntents.size());
// Finally, send one more registration-change intent, this time with a different account,
@@ -534,7 +539,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
assertTrue(InvalidationService.getIsClientStartedForTest());
InvalidationPreferences invPrefs = new InvalidationPreferences(getContext());
assertEquals(account, invPrefs.getSavedSyncedAccount());
- assertEquals(ImmutableSet.of(ModelType.ALL_TYPES_TYPE), invPrefs.getSavedSyncedTypes());
+ assertEquals(CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE),
+ invPrefs.getSavedSyncedTypes());
assertEquals(1, mStartServiceIntents.size());
assertTrue(isAndroidListenerStartIntent(mStartServiceIntents.get(0)));
@@ -544,8 +550,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Ensure registrations are correct.
Set<ObjectId> expectedTypes =
- ModelType.modelTypesToObjectIds(Sets.newHashSet(ModelType.values()));
- assertEquals(expectedTypes, Sets.newHashSet(getService().mRegistrations.get(0)));
+ ModelType.modelTypesToObjectIds(EnumSet.allOf(ModelType.class));
+ assertEquals(expectedTypes, new HashSet<ObjectId>(getService().mRegistrations.get(0)));
}
@SmallTest
@@ -557,14 +563,14 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Send register Intent with no desired types.
Account account = AccountManagerHelper.createAccountFromName("test@example.com");
Intent registrationIntent =
- IntentProtocol.createRegisterIntent(account, false, Sets.<ModelType>newHashSet());
+ IntentProtocol.createRegisterIntent(account, false, new HashSet<ModelType>());
getService().onHandleIntent(registrationIntent);
// Verify client started and state written.
assertTrue(InvalidationService.getIsClientStartedForTest());
InvalidationPreferences invPrefs = new InvalidationPreferences(getContext());
assertEquals(account, invPrefs.getSavedSyncedAccount());
- assertEquals(Sets.<String>newHashSet(), invPrefs.getSavedSyncedTypes());
+ assertEquals(new HashSet<String>(), invPrefs.getSavedSyncedTypes());
assertEquals(1, mStartServiceIntents.size());
assertTrue(isAndroidListenerStartIntent(mStartServiceIntents.get(0)));
@@ -579,8 +585,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Ensure registrations are correct.
assertEquals(1, getService().mRegistrations.size());
Set<ObjectId> expectedTypes =
- ModelType.modelTypesToObjectIds(Sets.newHashSet(ModelType.values()));
- assertEquals(expectedTypes, Sets.newHashSet(getService().mRegistrations.get(0)));
+ ModelType.modelTypesToObjectIds(EnumSet.allOf(ModelType.class));
+ assertEquals(expectedTypes, new HashSet<ObjectId>(getService().mRegistrations.get(0)));
}
@SmallTest
@@ -594,8 +600,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Send register Intent.
Account account = AccountManagerHelper.createAccountFromName("test@example.com");
- ImmutableSet<ModelType> desiredRegistrations =
- ImmutableSet.of(ModelType.BOOKMARK, ModelType.SESSION);
+ Set<ModelType> desiredRegistrations = CollectionUtil.newHashSet(
+ ModelType.BOOKMARK, ModelType.SESSION);
Intent registrationIntent = IntentProtocol.createRegisterIntent(account, false,
desiredRegistrations);
getService().onHandleIntent(registrationIntent);
@@ -622,8 +628,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
// Send register Intent. Verify client started but no registrations issued.
Account account = AccountManagerHelper.createAccountFromName("test@example.com");
- ImmutableSet<ModelType> desiredRegistrations =
- ImmutableSet.of(ModelType.BOOKMARK, ModelType.SESSION);
+ Set<ModelType> desiredRegistrations = CollectionUtil.newHashSet(
+ ModelType.BOOKMARK, ModelType.SESSION);
Set<ObjectId> desiredObjectIds = ModelType.modelTypesToObjectIds(desiredRegistrations);
Intent registrationIntent = IntentProtocol.createRegisterIntent(account, false,
@@ -650,7 +656,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio
actualRegisterIntent.getExtras().keySet());
assertEquals(
desiredObjectIds,
- Sets.newHashSet(getService().mRegistrations.get(0)));
+ new HashSet<ObjectId>(getService().mRegistrations.get(0)));
}
@SmallTest

Powered by Google App Engine
This is Rietveld 408576698