diff options
author | Scott Kennedy <skennedy@google.com> | 2013-02-25 16:40:35 -0800 |
---|---|---|
committer | Scott Kennedy <skennedy@google.com> | 2013-03-06 11:25:49 -0800 |
commit | 42ae8ba360efc42cc03d8e754a7ddd7dbd0ae92f (patch) | |
tree | 579c07190b0f93d6f0e53d9c259a3358347e946c /chips | |
parent | faa0e66bddef3f0d61a84636a79efddcd0fd78f8 (diff) | |
download | android_frameworks_ex-42ae8ba360efc42cc03d8e754a7ddd7dbd0ae92f.tar.gz android_frameworks_ex-42ae8ba360efc42cc03d8e754a7ddd7dbd0ae92f.tar.bz2 android_frameworks_ex-42ae8ba360efc42cc03d8e754a7ddd7dbd0ae92f.zip |
Unit test for getBetterRecipient()
Follow-up to Ic53d290431fcabce9607685a6eca45063fea0c9a
Change-Id: I28094ce9744838a1ab859470b22714d539ee8f4c
Diffstat (limited to 'chips')
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java | 1 | ||||
-rw-r--r-- | chips/tests/src/com/android/ex/chips/RecipientAlternatesAdapterTest.java | 56 |
2 files changed, 56 insertions, 1 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java index f825e93..07aa994 100644 --- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java +++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java @@ -229,7 +229,6 @@ public class RecipientAlternatesAdapter extends CursorAdapter { * Given two {@link RecipientEntry}s for the same email address, this will return the one that * contains more complete information for display purposes. Defaults to <code>entry2</code> if * no significant differences are found. - * TODO(skennedy) Add tests */ static RecipientEntry getBetterRecipient(final RecipientEntry entry1, final RecipientEntry entry2) { diff --git a/chips/tests/src/com/android/ex/chips/RecipientAlternatesAdapterTest.java b/chips/tests/src/com/android/ex/chips/RecipientAlternatesAdapterTest.java index f4b87c0..a1a1c7a 100644 --- a/chips/tests/src/com/android/ex/chips/RecipientAlternatesAdapterTest.java +++ b/chips/tests/src/com/android/ex/chips/RecipientAlternatesAdapterTest.java @@ -18,8 +18,13 @@ package com.android.ex.chips; import android.database.Cursor; import android.database.MatrixCursor; +import android.net.Uri; +import android.provider.ContactsContract.DisplayNameSources; import android.test.AndroidTestCase; +import com.android.ex.chips.RecipientAlternatesAdapter; +import com.android.ex.chips.RecipientEntry; + public class RecipientAlternatesAdapterTest extends AndroidTestCase { public void testRemoveDuplicateDestinations() { @@ -99,4 +104,55 @@ public class RecipientAlternatesAdapterTest extends AndroidTestCase { assertEquals(photoUri, c.getString(6)); assertEquals(displayNameSource, c.getInt(7)); } + + public void testGetBetterRecipient() { + // Ensure that if either (but not both) parameters are null, the other is returned + { + final RecipientEntry entry1 = + RecipientEntry.constructFakeEntry("1@android.com", true); + final RecipientEntry entry2 = null; + + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1); + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1); + } + + // Ensure that if only one has a display name, it is used + { + final RecipientEntry entry1 = + RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.NICKNAME, + "1@android.com", 0, null, 0, 0, (Uri) null, true); + final RecipientEntry entry2 = RecipientEntry.constructFakeEntry("1@android.com", true); + + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1); + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1); + } + + // Ensure that if one has a display name different from its destination, and the other's + // is equal to its destination, we use the unique one + { + final RecipientEntry entry1 = + RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.NICKNAME, + "1@android.com", 0, null, 0, 0, (Uri) null, true); + final RecipientEntry entry2 = + RecipientEntry.constructTopLevelEntry("2@android.com", DisplayNameSources.EMAIL, + "2@android.com", 0, null, 0, 0, (Uri) null, true); + + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1); + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1); + } + + // Ensure that if only one has a photo, it is used + { + final RecipientEntry entry1 = + RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.NICKNAME, + "1@android.com", 0, null, 0, 0, Uri.parse("http://www.android.com"), + true); + final RecipientEntry entry2 = + RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.EMAIL, + "2@android.com", 0, null, 0, 0, (Uri) null, true); + + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1); + assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1); + } + } } |