diff options
author | Zheng Fu <zhengfu@google.com> | 2015-04-01 15:36:27 -0700 |
---|---|---|
committer | Zheng Fu <zhengfu@google.com> | 2015-04-02 10:21:28 -0700 |
commit | 6012b85f0eef8ebcfcb73b72216d17893804d4ea (patch) | |
tree | 0396e72cb7aba8b3b49380a76347fa5d862eb2fa /tests | |
parent | bb1bc1a5b107e282f974e2a9f43307d0c2144c62 (diff) | |
download | packages_providers_ContactsProvider-6012b85f0eef8ebcfcb73b72216d17893804d4ea.zip packages_providers_ContactsProvider-6012b85f0eef8ebcfcb73b72216d17893804d4ea.tar.gz packages_providers_ContactsProvider-6012b85f0eef8ebcfcb73b72216d17893804d4ea.tar.bz2 |
Add some new method implementations for new contact aggregator.
Also add a ContactAggregatorHelper class to hold some helper methods
to better falicitate unit testing
Bug:19908937
Change-Id: I2e2bcef2228e7a171e9c3259c27c3fa28bde646c
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java | 38 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/aggregation/util/ContactAggregatorHelperTest.java | 118 |
2 files changed, 118 insertions, 38 deletions
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java index 43fc488..12f0ba8 100644 --- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java +++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java @@ -1765,44 +1765,6 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { assertTrue(queryContactId(newId) > 0); } - public void testFindConnectedRawContacts() { - Set<Long> rawContactIdSet = new HashSet<Long>(); - rawContactIdSet.addAll(Arrays.asList(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l)); - - Multimap<Long, Long> matchingrawIdPairs = HashMultimap.create(); - matchingrawIdPairs.put(1l, 2l); - matchingrawIdPairs.put(2l, 1l); - - matchingrawIdPairs.put(1l, 7l); - matchingrawIdPairs.put(7l, 1l); - - matchingrawIdPairs.put(2l, 3l); - matchingrawIdPairs.put(3l, 2l); - - matchingrawIdPairs.put(2l, 8l); - matchingrawIdPairs.put(8l, 2l); - - matchingrawIdPairs.put(8l, 9l); - matchingrawIdPairs.put(9l, 8l); - - matchingrawIdPairs.put(4l, 5l); - matchingrawIdPairs.put(5l, 4l); - - Set<Set<Long>> actual = ContactAggregator.findConnectedComponents(rawContactIdSet, - matchingrawIdPairs); - - Set<Set<Long>> expected = new HashSet<Set<Long>>(); - Set<Long> result1 = new HashSet<Long>(); - result1.addAll(Arrays.asList(1l, 2l, 3l, 7l, 8l, 9l)); - Set<Long> result2 = new HashSet<Long>(); - result2.addAll(Arrays.asList(4l, 5l)); - Set<Long> result3 = new HashSet<Long>(); - result3.addAll(Arrays.asList(6l)); - expected.addAll(Arrays.asList(result1, result2, result3)); - - assertEquals(expected, actual); - } - private void assertSuggestions(long contactId, long... suggestions) { final Uri aggregateUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); Uri uri = Uri.withAppendedPath(aggregateUri, diff --git a/tests/src/com/android/providers/contacts/aggregation/util/ContactAggregatorHelperTest.java b/tests/src/com/android/providers/contacts/aggregation/util/ContactAggregatorHelperTest.java new file mode 100644 index 0000000..4373a76 --- /dev/null +++ b/tests/src/com/android/providers/contacts/aggregation/util/ContactAggregatorHelperTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.providers.contacts.aggregation.util; + +import android.test.MoreAsserts; +import android.test.suitebuilder.annotation.SmallTest; +import com.google.android.collect.Sets; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import junit.framework.TestCase; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@SmallTest +public class ContactAggregatorHelperTest extends TestCase { + + private static final long ACCOUNT_1 = 1; + private static final long ACCOUNT_2 = 2; + private static final long ACCOUNT_3 = 3; + private static final long ACCOUNT_4 = 4; + private static final long ACCOUNT_5 = 5; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testMergeComponentsWithDisjointAccounts() { + Set<Set<Long>> connectedRawContactSets = new HashSet<>(); + Map<Long, Long> rawContactsToAccounts = new HashMap<>(); + for (long i = 100; i < 108; ) { + Set<Long> rawContactSet = new HashSet<>(); + rawContactSet.add(i++); + rawContactSet.add(i++); + connectedRawContactSets.add(rawContactSet); + } + + for (long i = 100; i < 103; i++) { + rawContactsToAccounts.put(i, ACCOUNT_1); + } + rawContactsToAccounts.put(100l, ACCOUNT_1); + rawContactsToAccounts.put(101l, ACCOUNT_1); + rawContactsToAccounts.put(102l, ACCOUNT_1); + rawContactsToAccounts.put(103l, ACCOUNT_2); + rawContactsToAccounts.put(104l, ACCOUNT_3); + rawContactsToAccounts.put(105l, ACCOUNT_4); + rawContactsToAccounts.put(106l, ACCOUNT_5); + rawContactsToAccounts.put(107l, ACCOUNT_5); + // Component1: [rawContactId=100, accountId=1; raw_contactId=101, accountId=1] + // Component2: [rawContactId=102, accountId=1; raw_contactId=103, accountId=2] + // Component3: [rawContactId=104, accountId=3; raw_contactId=105, accountId=4] + // Component4: [rawContactId=106, accountId=5; raw_contactId=107, accountId=5] + // Component3 and component4 can be merged because they have disjoint accounts, but cannot + // merge with either component1 or component2 due to the uncertainty. + + ContactAggregatorHelper.mergeComponentsWithDisjointAccounts(connectedRawContactSets, + rawContactsToAccounts); + + MoreAsserts.assertContentsInAnyOrder(connectedRawContactSets, Sets.newHashSet(100l, + 101l), Sets.newHashSet(102l, 103l), Sets.newHashSet(104l, 105l, 106l, 107l)); + } + + public void testFindConnectedRawContacts() { + Set<Long> rawContactIdSet = new HashSet<>(); + rawContactIdSet.addAll(Arrays.asList(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l)); + + Multimap<Long, Long> matchingrawIdPairs = HashMultimap.create(); + matchingrawIdPairs.put(1l, 2l); + matchingrawIdPairs.put(2l, 1l); + + matchingrawIdPairs.put(1l, 7l); + matchingrawIdPairs.put(7l, 1l); + + matchingrawIdPairs.put(2l, 3l); + matchingrawIdPairs.put(3l, 2l); + + matchingrawIdPairs.put(2l, 8l); + matchingrawIdPairs.put(8l, 2l); + + matchingrawIdPairs.put(8l, 9l); + matchingrawIdPairs.put(9l, 8l); + + matchingrawIdPairs.put(4l, 5l); + matchingrawIdPairs.put(5l, 4l); + + Set<Set<Long>> actual = ContactAggregatorHelper.findConnectedComponents(rawContactIdSet, + matchingrawIdPairs); + + Set<Set<Long>> expected = new HashSet<>(); + Set<Long> result1 = new HashSet<>(); + result1.addAll(Arrays.asList(1l, 2l, 3l, 7l, 8l, 9l)); + Set<Long> result2 = new HashSet<>(); + result2.addAll(Arrays.asList(4l, 5l)); + Set<Long> result3 = new HashSet<>(); + result3.addAll(Arrays.asList(6l)); + expected.addAll(Arrays.asList(result1, result2, result3)); + + assertEquals(expected, actual); + } +} |