FileDocCategorySizeDatePackage
Rfc822ValidatorTest.javaAPI DocAndroid 5.1 API5616Thu Mar 12 22:22:48 GMT 2015com.android.common

Rfc822ValidatorTest

public class Rfc822ValidatorTest extends TestCase

Fields Summary
static final String[]
VALID_EMAILS
static final String[]
INVALID_EMAILS
Constructors Summary
Methods Summary
public voidtestEmailValidator()


    
       
        Rfc822Validator validator = new Rfc822Validator("gmail.com");

        for (String email : VALID_EMAILS) {
            assertTrue(email + " should be a valid email address", validator.isValid(email));
        }

        for (String email : INVALID_EMAILS) {
            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>");
        fixes.put("()~><@not.work", "");

        for (Map.Entry<String, String> e : fixes.entrySet()) {
            assertEquals(e.getValue(), validator.fixText(e.getKey()).toString());
        }
    
public voidtestEmailValidatorNullDomain()

        Rfc822Validator validator = new Rfc822Validator(null);

        Map<String, String> fixes = new HashMap<String, String>();
        fixes.put("a", "<a>");
        fixes.put("a b", "<a b>");
        fixes.put("a@b", "<a@b>");
        fixes.put("a@b.com", "<a@b.com>"); // this one is correct

        for (Map.Entry<String, String> e : fixes.entrySet()) {
            assertEquals(e.getValue(), validator.fixText(e.getKey()).toString());
        }
    
public voidtestEmailValidatorRemoveInvalid()

        Rfc822Validator validator = new Rfc822Validator("google.com");
        validator.setRemoveInvalid(true);

        Map<String, String> fixes = new HashMap<String, String>();
        fixes.put("a", "");
        fixes.put("a b", "");
        fixes.put("a@b", "");
        fixes.put("a@b.com", "<a@b.com>"); // this one is correct

        for (Map.Entry<String, String> e : fixes.entrySet()) {
            assertEquals(e.getValue(), validator.fixText(e.getKey()).toString());
        }