diff options
author | Scott Kennedy <skennedy@google.com> | 2013-03-22 09:42:03 -0700 |
---|---|---|
committer | Scott Kennedy <skennedy@google.com> | 2013-03-22 09:44:08 -0700 |
commit | 983c99b9e00913e8d2a5642cd05ccb9a81570be7 (patch) | |
tree | 6e35c3ba37d803839fc1f448f0a359c2e9d6ff72 /tests | |
parent | b315ee2049ac0942d922993d57ef825d86409883 (diff) | |
download | chips-983c99b9e00913e8d2a5642cd05ccb9a81570be7.tar.gz |
Add unit test for creating fake phone entries
There was a problem with numbers formatted like:
"(888) 555-1234".
Bug: 8449554
Change-Id: Ic70998104bd5151aba2dca5202bc4f99ced362be
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/ex/chips/ChipsTest.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/src/com/android/ex/chips/ChipsTest.java b/tests/src/com/android/ex/chips/ChipsTest.java index 217594d..7963086 100644 --- a/tests/src/com/android/ex/chips/ChipsTest.java +++ b/tests/src/com/android/ex/chips/ChipsTest.java @@ -28,11 +28,14 @@ import android.text.style.ImageSpan; import android.text.util.Rfc822Tokenizer; import android.widget.TextView; +import com.android.ex.chips.BaseRecipientAdapter; import com.android.ex.chips.RecipientEditTextView; import com.android.ex.chips.RecipientEntry; import com.android.ex.chips.recipientchip.DrawableRecipientChip; import com.android.ex.chips.recipientchip.VisibleRecipientChip;; +import java.util.regex.Pattern; + @SmallTest public class ChipsTest extends AndroidTestCase { private DrawableRecipientChip[] mMockRecips; @@ -122,9 +125,14 @@ public class ChipsTest extends AndroidTestCase { } private class TestBaseRecipientAdapter extends BaseRecipientAdapter { - public TestBaseRecipientAdapter(Context context) { + public TestBaseRecipientAdapter(final Context context) { super(context); } + + public TestBaseRecipientAdapter(final Context context, final int preferredMaxResultCount, + final int queryMode) { + super(context, preferredMaxResultCount, queryMode); + } } private MockRecipientEditTextView createViewForTesting() { @@ -990,4 +998,31 @@ public class ChipsTest extends AndroidTestCase { assertEquals(email.replaceAll(",\\s*$", ""), view.mTemporaryRecipients.get(0).getOriginalText().toString().trim()); } + + public void testCreateTokenizedEntryForPhone() { + final String phonePattern = "[^\\d]*888[^\\d]*555[^\\d]*1234[^\\d]*"; + final String phone1 = "8885551234"; + final String phone2 = "888-555-1234"; + final String phone3 = "(888) 555-1234"; + + final RecipientEditTextView view = new RecipientEditTextView(getContext(), null); + final BaseRecipientAdapter adapter = new TestBaseRecipientAdapter(getContext(), 10, + BaseRecipientAdapter.QUERY_TYPE_PHONE); + view.setAdapter(adapter); + + final RecipientEntry entry1 = view.createTokenizedEntry(phone1); + final String destination1 = entry1.getDestination(); + assertTrue(phone1 + " failed with " + destination1, + Pattern.matches(phonePattern, destination1)); + + final RecipientEntry entry2 = view.createTokenizedEntry(phone2); + final String destination2 = entry2.getDestination(); + assertTrue(phone2 + " failed with " + destination2, + Pattern.matches(phonePattern, destination2)); + + final RecipientEntry entry3 = view.createTokenizedEntry(phone3); + final String destination3 = entry3.getDestination(); + assertTrue(phone3 + " failed with " + destination3, + Pattern.matches(phonePattern, destination3)); + } } |