Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3671725b authored by Yorke Lee's avatar Yorke Lee
Browse files

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
parent 3ff9c116
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -456,8 +456,9 @@
    <!-- String describing the icon used to start a voice search -->
    <string name="description_start_voice_search">Start voice search</string>

    <!-- The string used to represent an unknown location for a phone number in the call log [CHAR LIMIT=3] -->
    <string name="call_log_empty_gecode">\u0020</string>
    <!-- The string used to represent an unknown location for a phone number in the call log
        Do not translate. -->
    <string name="call_log_empty_geocode"></string>

    <!-- Menu item used to call a contact, containing the number of the contact to call -->
    <string name="menu_callNumber">Call <xliff:g id="number">%s</xliff:g></string>
+2 −3
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ public class PhoneCallDetailsHelper {
            PhoneNumberUtilsWrapper phoneUtils) {
        mResources = resources;
        mCallTypeHelper = callTypeHelper;
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(resources);
        mPhoneNumberUtilsWrapper = phoneUtils;
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(mPhoneNumberUtilsWrapper, resources);
    }

    /** Fills the call details views with content. */
@@ -122,7 +122,7 @@ public class PhoneCallDetailsHelper {
            nameText = displayNumber;
            if (TextUtils.isEmpty(details.geocode)
                    || mPhoneNumberUtilsWrapper.isVoicemailNumber(details.number)) {
                numberText = mResources.getString(R.string.call_log_empty_gecode);
                numberText = mResources.getString(R.string.call_log_empty_geocode);
            } else {
                numberText = details.geocode;
            }
@@ -137,7 +137,6 @@ public class PhoneCallDetailsHelper {
        }

        views.nameView.setText(nameText);

        views.labelView.setText(labelText);
        views.labelView.setVisibility(TextUtils.isEmpty(labelText) ? View.GONE : View.VISIBLE);
    }
+9 −3
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ package com.android.dialer.calllog;

import android.content.res.Resources;
import android.provider.CallLog.Calls;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;

import com.android.dialer.R;

@@ -27,10 +27,17 @@ import com.android.dialer.R;
 * Helper for formatting and managing the display of phone numbers.
 */
public class PhoneNumberDisplayHelper {
    private final PhoneNumberUtilsWrapper mPhoneNumberUtils;
    private final Resources mResources;

    public PhoneNumberDisplayHelper(Resources resources) {
        mResources = resources;
        mPhoneNumberUtils = new PhoneNumberUtilsWrapper();
    }

    public PhoneNumberDisplayHelper(PhoneNumberUtilsWrapper phoneNumberUtils, Resources resources) {
        mPhoneNumberUtils = phoneNumberUtils;
        mResources = resources;
    }

    /* package */ CharSequence getDisplayName(CharSequence number, int presentation) {
@@ -43,7 +50,7 @@ public class PhoneNumberDisplayHelper {
        if (presentation == Calls.PRESENTATION_PAYPHONE) {
            return mResources.getString(R.string.payphone);
        }
        if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) {
        if (mPhoneNumberUtils.isVoicemailNumber(number)) {
            return mResources.getString(R.string.voicemail);
        }
        if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) {
@@ -62,7 +69,6 @@ public class PhoneNumberDisplayHelper {
            int presentation, CharSequence formattedNumber) {

        final CharSequence displayName = getDisplayName(number, presentation);

        if (!TextUtils.isEmpty(displayName)) {
            return displayName;
        }
+5 −5
Original line number Diff line number Diff line
@@ -1561,8 +1561,8 @@ public class DialpadFragment extends Fragment
     */
    private void updateDialString(char newDigit) {
        if (newDigit != WAIT && newDigit != PAUSE) {
            Log.wtf(TAG, "Not expected for anything other than PAUSE & WAIT");
            return;
            throw new IllegalArgumentException(
                    "Not expected for anything other than PAUSE & WAIT");
        }

        int selectionStart;
@@ -1642,8 +1642,8 @@ public class DialpadFragment extends Fragment
    /* package */ static boolean canAddDigit(CharSequence digits, int start, int end,
                                             char newDigit) {
        if(newDigit != WAIT && newDigit != PAUSE) {
            Log.wtf(TAG, "Should not be called for anything other than PAUSE & WAIT");
            return false;
            throw new IllegalArgumentException(
                    "Should not be called for anything other than PAUSE & WAIT");
        }

        // False if no selection, or selection is reversed (end < start)
+5 −3
Original line number Diff line number Diff line
@@ -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() {
Loading