diff options
-rw-r--r-- | src/com/android/dialer/calllog/ContactInfoHelper.java | 10 | ||||
-rw-r--r-- | tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java | 27 |
2 files changed, 30 insertions, 7 deletions
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 4b9d5532a..e760750b2 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -170,7 +170,7 @@ public class ContactInfoHelper { } String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY); ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey); - contactInfo.nameAlternative = lookUpDisplayNameAlternative(lookupKey); + contactInfo.nameAlternative = lookUpDisplayNameAlternative(mContext, lookupKey); return contactInfo; } finally { phoneLookupCursor.close(); @@ -193,10 +193,14 @@ public class ContactInfoHelper { return info; } - private String lookUpDisplayNameAlternative(String lookupKey) { + public static String lookUpDisplayNameAlternative(Context context, String lookupKey) { + if (lookupKey == null) { + return null; + } + Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey); - Cursor cursor = mContext.getContentResolver().query(uri, + Cursor cursor = context.getContentResolver().query(uri, PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, null, null, null); if (cursor == null) { diff --git a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java index 6db738443..588a27fcf 100644 --- a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java +++ b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java @@ -57,11 +57,11 @@ public class ContactInfoHelperTest extends AndroidTestCase { mContactInfoHelper = new ContactInfoHelper(mContext, TEST_COUNTRY_ISO); } - public void testLookupContactFromUriNullUri() { + public void testLookupContactFromUri_NullUri() { Assert.assertNull(mContactInfoHelper.lookupContactFromUri(null)); } - public void testLookupContactFromUriNoResults() { + public void testLookupContactFromUri_NoResults() { setUpQueryExpectations(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, PhoneQuery.PHONE_LOOKUP_PROJECTION); @@ -70,7 +70,7 @@ public class ContactInfoHelperTest extends AndroidTestCase { mContext.verify(); } - public void testLookupContactFromUriNoDisplayNameAlternative() { + public void testLookupContactFromUri_NoDisplayNameAlternative() { setUpQueryExpectations(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, PhoneQuery.PHONE_LOOKUP_PROJECTION, TEST_LOOKUP_ROW); setUpQueryExpectations(displayNameAlternativeUri, @@ -83,7 +83,7 @@ public class ContactInfoHelperTest extends AndroidTestCase { mContext.verify(); } - public void testLookupContactFromUriWithDisplayNameAlternative() { + public void testLookupContactFromUri_HasDisplayNameAlternative() { setUpQueryExpectations(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, PhoneQuery.PHONE_LOOKUP_PROJECTION, TEST_LOOKUP_ROW); setUpQueryExpectations(displayNameAlternativeUri, @@ -96,6 +96,25 @@ public class ContactInfoHelperTest extends AndroidTestCase { mContext.verify(); } + public void testLookupDisplayNameAlternative_NullLookup() { + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, null)); + } + + public void testLookupDisplayNameAlternative_NoResults() { + setUpQueryExpectations(displayNameAlternativeUri, + PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION); + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY)); + mContext.verify(); + } + + public void testLookupDisplayNameAlternative_HasDisplayNameAlternative() { + setUpQueryExpectations(displayNameAlternativeUri, + PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, TEST_DISPLAY_NAME_ALTERNATIVE_ROW); + Assert.assertEquals(TEST_DISPLAY_NAME_ALTERNATIVE, + mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY)); + mContext.verify(); + } + /* * Sets up query expectations to return the given row for all queries for the given * uri and projection. If row is null, an empty cursor is returned for query calls |