diff options
| author | Paul Westbrook <pwestbro@google.com> | 2010-09-30 03:23:52 -0700 |
|---|---|---|
| committer | Paul Westbrook <pwestbro@google.com> | 2010-09-30 11:30:12 -0700 |
| commit | b4f5e0e5755938f2be9a2f1a1a6609b018c530ad (patch) | |
| tree | 070db6608ef583fc6980c4b77613a45e72d13657 /common/tests/src | |
| parent | 575e19825099eb83d1d452ffce93314aa66432ed (diff) | |
| download | android_frameworks_ex-b4f5e0e5755938f2be9a2f1a1a6609b018c530ad.tar.gz android_frameworks_ex-b4f5e0e5755938f2be9a2f1a1a6609b018c530ad.tar.bz2 android_frameworks_ex-b4f5e0e5755938f2be9a2f1a1a6609b018c530ad.zip | |
Fixed the Rfc822Validator
Make sure that the validator doesn't consider an email address
that has a domain that has more than one adjacent '.' characters valid
Bug: 3048703
Change-Id: I1c227f393738850d89b6da52693d806c231f3136
Diffstat (limited to 'common/tests/src')
| -rw-r--r-- | common/tests/src/com/android/common/Rfc822ValidatorTest.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/common/tests/src/com/android/common/Rfc822ValidatorTest.java b/common/tests/src/com/android/common/Rfc822ValidatorTest.java new file mode 100644 index 0000000..5118146 --- /dev/null +++ b/common/tests/src/com/android/common/Rfc822ValidatorTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.common; + +import android.test.suitebuilder.annotation.SmallTest; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +public class Rfc822ValidatorTest extends TestCase { + + @SmallTest + public void testEmailValidator() { + Rfc822Validator validator = new Rfc822Validator("gmail.com"); + String[] validEmails = new String[] { + "a@b.com", "a@b.fr", "a+b@c.com", "a@b.info", "john@example.com", "john@example.fr", + "john@corp.example.com", + }; + + for (String email : validEmails) { + assertTrue(email + " should be a valid email address", validator.isValid(email)); + } + + String[] invalidEmails = new String[] { + "a", "a@b", "a b", "a@b.12", "john@example..com", "johnexample.com", "john.example.com" + }; + + for (String email : invalidEmails) { + assertFalse(email + " should not be a valid email address", validator.isValid(email)); + } + + Map<String, String> fixes = new HashMap<String, String>(); + fixes.put("a", "<a@gmail.com>"); + fixes.put("a b", "<ab@gmail.com>"); + fixes.put("a@b", "<a@b>"); + + for (Map.Entry<String, String> e : fixes.entrySet()) { + assertEquals(e.getValue(), validator.fixText(e.getKey()).toString()); + } + } +} |
