diff options
author | Brandon Maxwell <maxwelb@google.com> | 2015-11-02 11:28:35 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2015-11-03 15:47:39 -0800 |
commit | ab4443c7e235e0feebca7eadf70ecd9bd2455b46 (patch) | |
tree | f78f94a64037c39046f3a82c2b13e13b39962dca | |
parent | 7d048b14177813c9c2b857c67d69698af466a5c7 (diff) |
Changing method to public, static for use in InCallUi
+ Changed ContactInfoHelper.lookUpDisplayNameAlternative to public so
it's usable in InCallUi
+ Changed ContactInfoHelper.lookUpDisplayNamealternative to static to
cut down on object creation
+ Added tests for lookUpDisplayNameAlternative since it is public
Change-Id: Iede746655a1ca773cb0cd8cf26df665e34ab47fc
-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 |