diff options
author | Yorke Lee <yorkelee@google.com> | 2013-11-20 15:02:49 -0800 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2014-03-04 20:03:52 +0000 |
commit | ef793edd768d25b43bc4ea597ae68fa0d742be74 (patch) | |
tree | b7416b2add3080d1a9be4451298bf8c3c91fe1b4 /tests | |
parent | c5b35dd8c6a5af6a4b82fc83e3b25801eace525f (diff) |
Fix Dialer tests
* Empty geocode is now " " instead of "-" per UX request
* DialpadFragment now throws IllegalArgumentException instead
of Log.wtf so that it can be tested
* Added contact id column to contactsprovider query
* Modified PhoneNumberDisplayHelper to take an instance of
PhoneNumberUtilsWrapper so that it can be mocked out
Fix label-related tests that were failing due to a change in how we
treat empty labels
Bug: 9111164
Change-Id: If2244586b9d09fa2839fa0ddfc9f369f9dc66e51
(cherry picked from commit 3671725b58a9768016e141c77424dedb5fd2c55a)
Diffstat (limited to 'tests')
6 files changed, 43 insertions, 25 deletions
diff --git a/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java index 6a9817f26..6f5a98658 100644 --- a/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java +++ b/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java @@ -51,6 +51,8 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { private static final String TEST_COUNTRY_ISO = "US"; /** The geocoded location used in the tests. */ private static final String TEST_GEOCODE = "United States"; + /** Empty geocode label */ + private static final String EMPTY_GEOCODE = ""; /** The object under test. */ private PhoneCallDetailsHelper mHelper; @@ -183,18 +185,18 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { public void testSetPhoneCallDetails_NoGeocode() { setPhoneCallDetailsWithNumberAndGeocode("+14125555555", "1-412-555-5555", null); assertNameEquals("1-412-555-5555"); // The phone number is shown as the name. - assertLabelEquals("-"); // The empty geocode is shown as the label. + assertLabelEquals(EMPTY_GEOCODE); // The empty geocode is shown as the label. } public void testSetPhoneCallDetails_EmptyGeocode() { setPhoneCallDetailsWithNumberAndGeocode("+14125555555", "1-412-555-5555", ""); assertNameEquals("1-412-555-5555"); // The phone number is shown as the name. - assertLabelEquals("-"); // The empty geocode is shown as the label. + assertLabelEquals(EMPTY_GEOCODE); // The empty geocode is shown as the label. } public void testSetPhoneCallDetails_NoGeocodeForVoicemail() { setPhoneCallDetailsWithNumberAndGeocode(TEST_VOICEMAIL_NUMBER, "", "United States"); - assertLabelEquals("-"); // The empty geocode is shown as the label. + assertLabelEquals(EMPTY_GEOCODE); // The empty geocode is shown as the label. } public void testSetPhoneCallDetails_Highlighted() { diff --git a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java index 7ceec8f08..4ccdaaf33 100644 --- a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java @@ -70,6 +70,8 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2<Fragme /** The formatted version of {@link #TEST_NUMBER}. */ private static final String TEST_FORMATTED_NUMBER = "1 212-555-1000"; + private static final String TEST_DEFAULT_CUSTOM_LABEL = "myLabel"; + /** The activity in which we are hosting the fragment. */ private FragmentTestActivity mActivity; private CallLogFragment mFragment; @@ -218,8 +220,10 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2<Fragme @MediumTest public void testBindView_WithCachedName() { mCursor.moveToFirst(); + // provide a default custom label instead of an empty string, which corresponds to + // {@value com.android.dialer.calllog.ContactInfo#GEOCODE_AS_LABEL} insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE, - "John Doe", Phone.TYPE_HOME, ""); + "John Doe", Phone.TYPE_HOME, TEST_DEFAULT_CUSTOM_LABEL); View view = mAdapter.newStandAloneView(getActivity(), mParentView); mAdapter.bindStandAloneView(view, getActivity(), mCursor); @@ -232,20 +236,22 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2<Fragme public void testBindView_UriNumber() { mCursor.moveToFirst(); insertWithCachedValues("sip:johndoe@gmail.com", NOW, 0, Calls.INCOMING_TYPE, - "John Doe", Phone.TYPE_HOME, ""); + "John Doe", Phone.TYPE_HOME, TEST_DEFAULT_CUSTOM_LABEL); View view = mAdapter.newStandAloneView(getActivity(), mParentView); mAdapter.bindStandAloneView(view, getActivity(), mCursor); CallLogListItemViews views = (CallLogListItemViews) view.getTag(); assertNameIs(views, "John Doe"); - assertLabel(views, "sip:johndoe@gmail.com", null); + assertLabel(views, "sip:johndoe@gmail.com", "sip:johndoe@gmail.com"); } @MediumTest public void testBindView_HomeLabel() { mCursor.moveToFirst(); + // provide a default custom label instead of an empty string, which corresponds to + // {@value com.android.dialer.calllog.ContactInfo#GEOCODE_AS_LABEL} insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE, - "John Doe", Phone.TYPE_HOME, ""); + "John Doe", Phone.TYPE_HOME, TEST_DEFAULT_CUSTOM_LABEL); View view = mAdapter.newStandAloneView(getActivity(), mParentView); mAdapter.bindStandAloneView(view, getActivity(), mCursor); @@ -257,8 +263,10 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2<Fragme @MediumTest public void testBindView_WorkLabel() { mCursor.moveToFirst(); + // provide a default custom label instead of an empty string, which corresponds to + // {@link com.android.dialer.calllog.ContactInfo#GEOCODE_AS_LABEL} insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE, - "John Doe", Phone.TYPE_WORK, ""); + "John Doe", Phone.TYPE_WORK, TEST_DEFAULT_CUSTOM_LABEL); View view = mAdapter.newStandAloneView(getActivity(), mParentView); mAdapter.bindStandAloneView(view, getActivity(), mCursor); @@ -607,7 +615,9 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2<Fragme privateOrUnknownOrVm[2] = true; } else { int inout = mRnd.nextBoolean() ? Calls.OUTGOING_TYPE : Calls.INCOMING_TYPE; - String number = new Formatter().format("1800123%04d", i).toString(); + final Formatter formatter = new Formatter(); + String number = formatter.format("1800123%04d", i).toString(); + formatter.close(); insert(number, Calls.PRESENTATION_ALLOWED, NOW, RAND_DURATION, inout); } } diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index 662afa0ca..a10dec908 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -50,6 +50,7 @@ public class CallLogListItemHelperTest extends AndroidTestCase { /** The views used in the tests. */ private CallLogListItemViews mViews; private PhoneNumberDisplayHelper mPhoneNumberHelper; + private PhoneNumberDisplayHelper mPhoneNumberDisplayHelper; @Override protected void setUp() throws Exception { @@ -61,7 +62,9 @@ public class CallLogListItemHelperTest extends AndroidTestCase { TEST_VOICEMAIL_NUMBER); PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper( resources, callTypeHelper, phoneUtils); - mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mPhoneNumberHelper, resources); + mPhoneNumberDisplayHelper = new PhoneNumberDisplayHelper(resources); + mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mPhoneNumberDisplayHelper, + resources); mViews = CallLogListItemViews.createForTest(context); } diff --git a/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java b/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java index 95f3cc12e..7266d8890 100644 --- a/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java +++ b/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java @@ -16,8 +16,6 @@ package com.android.dialer.calllog; -import android.content.res.Resources; - /** * Modified version of {@link com.android.dialer.calllog.PhoneNumberDisplayHelper} to be used in tests * that allows injecting the voicemail number. diff --git a/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java b/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java index a123e745e..6f18fe69a 100644 --- a/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java +++ b/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java @@ -34,7 +34,11 @@ public class DialpadFragmentTest extends TestCase { public void testCanAddDigit_InvalidCharacter() { // only handles wait/pause - assertFalse(DialpadFragment.canAddDigit("123", 1, 1, '5')); + try { + DialpadFragment.canAddDigit("123", 1, 1, '5'); + fail("Calling canAddDigit with invalid character should throw an exception"); + } catch (IllegalArgumentException e) { + } } public void testCanAddDigit_BadOrNoSelection() { diff --git a/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java b/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java index f86675e57..fbc64cd64 100644 --- a/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java +++ b/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java @@ -91,7 +91,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, 13); expectQuery(contactUri) .returnRow(1, "123", 0, null, null, Phone.TYPE_HOME, null, - Phone.CONTENT_ITEM_TYPE); + Phone.CONTENT_ITEM_TYPE, 13); TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction( mContext, ContactDisplayUtils.INTERACTION_SMS, null); @@ -110,7 +110,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { Uri dataUri = ContentUris.withAppendedId(Data.CONTENT_URI, 1); expectQuery(dataUri, true /* isDataUri */ ) .returnRow(1, "987", 0, null, null, Phone.TYPE_HOME, null, - Phone.CONTENT_ITEM_TYPE); + Phone.CONTENT_ITEM_TYPE, 1); TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction( mContext, ContactDisplayUtils.INTERACTION_SMS, null); @@ -128,10 +128,10 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { public void testSendSmsWhenThereIsPrimaryNumber() { Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, 13); expectQuery(contactUri) - .returnRow( - 1, "123", 0, null, null, Phone.TYPE_HOME, null, Phone.CONTENT_ITEM_TYPE) - .returnRow( - 2, "456", 1, null, null, Phone.TYPE_HOME, null, Phone.CONTENT_ITEM_TYPE); + .returnRow(1, "123", 0, null, null, Phone.TYPE_HOME, null, + Phone.CONTENT_ITEM_TYPE, 13) + .returnRow(2, "456", 1, null, null, Phone.TYPE_HOME, null, + Phone.CONTENT_ITEM_TYPE, 13); TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction( mContext, ContactDisplayUtils.INTERACTION_SMS, null); @@ -170,9 +170,9 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, 13); expectQuery(contactUri) .returnRow(1, "123", 0, null, null, Phone.TYPE_HOME, null, - Phone.CONTENT_ITEM_TYPE) + Phone.CONTENT_ITEM_TYPE, 13) .returnRow(2, "123", 0, null, null, Phone.TYPE_WORK, null, - Phone.CONTENT_ITEM_TYPE); + Phone.CONTENT_ITEM_TYPE, 13); TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction( mContext, ContactDisplayUtils.INTERACTION_CALL, null); @@ -191,7 +191,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, 13); expectQuery(contactUri) .returnRow(1, "example@example.com", 0, null, null, Phone.TYPE_HOME, null, - SipAddress.CONTENT_ITEM_TYPE); + SipAddress.CONTENT_ITEM_TYPE, 13); TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction( mContext, ContactDisplayUtils.INTERACTION_CALL, null); @@ -209,9 +209,9 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, 13); expectQuery(contactUri) .returnRow(1, "123", 0, "account", null, Phone.TYPE_HOME, "label", - Phone.CONTENT_ITEM_TYPE) + Phone.CONTENT_ITEM_TYPE, 13) .returnRow(2, "456", 0, null, null, Phone.TYPE_WORK, null, - Phone.CONTENT_ITEM_TYPE); + Phone.CONTENT_ITEM_TYPE, 13); TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction( mContext, ContactDisplayUtils.INTERACTION_CALL, null); @@ -252,7 +252,8 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { RawContacts.DATA_SET, Phone.TYPE, Phone.LABEL, - Phone.MIMETYPE) + Phone.MIMETYPE, + Phone.CONTACT_ID) .withSelection("mimetype IN ('vnd.android.cursor.item/phone_v2'," + " 'vnd.android.cursor.item/sip_address') AND data1 NOT NULL"); } |