diff options
author | Scott Kennedy <skennedy@google.com> | 2013-03-22 17:08:05 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-03-22 17:08:05 +0000 |
commit | 8f0f70c88a16f784deddfc1511503226b17798ca (patch) | |
tree | 03eb17914af1f8d3e07be506def93609c22c2449 | |
parent | b560197a9d2f056545e54cd4746b8ce6dde9c629 (diff) | |
parent | f5ecf6ad067fb1036199ad5125949aae7ffd9689 (diff) | |
download | android_frameworks_ex-8f0f70c88a16f784deddfc1511503226b17798ca.tar.gz android_frameworks_ex-8f0f70c88a16f784deddfc1511503226b17798ca.tar.bz2 android_frameworks_ex-8f0f70c88a16f784deddfc1511503226b17798ca.zip |
am f5ecf6ad: Add unit test for creating fake phone entries
* commit 'f5ecf6ad067fb1036199ad5125949aae7ffd9689':
Add unit test for creating fake phone entries
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientEditTextView.java | 3 | ||||
-rw-r--r-- | chips/tests/src/com/android/ex/chips/ChipsTest.java | 37 |
2 files changed, 38 insertions, 2 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index 8659103..e40edf1 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -1005,7 +1005,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements return match.matches(); } - private RecipientEntry createTokenizedEntry(String token) { + // VisibleForTesting + RecipientEntry createTokenizedEntry(final String token) { if (TextUtils.isEmpty(token)) { return null; } diff --git a/chips/tests/src/com/android/ex/chips/ChipsTest.java b/chips/tests/src/com/android/ex/chips/ChipsTest.java index 217594d..7963086 100644 --- a/chips/tests/src/com/android/ex/chips/ChipsTest.java +++ b/chips/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)); + } } |