EmailAddressUtil { public static boolean isValid(final EmailAddress emailAddress) { return isValid(emailAddress.getEmail()); }  static String toString(EmailAddress emailAddress); static String toHeaderValue(Collection<EmailAddress> emailAddresses); static boolean equalCollections(final Collection<EmailAddress> a, final Collection<EmailAddress> b); static boolean isValid(final EmailAddress emailAddress); static boolean isValid(final String email); static Collection<EmailAddress> parse(final String userInput); static String shorten(final String input);  }
@Test public void validEmailAddresses() { Assert.assertTrue(EmailAddressUtil.isValid("simple@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("very.common@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("disposable.style.email.with+symbol@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("other.email-with-hyphen@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("fully-qualified-domain@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("user.name+tag+sorting@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("x@example.com")); Assert.assertTrue(EmailAddressUtil.isValid("example-indeed@strange-example.com")); Assert.assertTrue(EmailAddressUtil.isValid("admin@mailserver1")); Assert.assertTrue(EmailAddressUtil.isValid("example@s.example")); Assert.assertTrue(EmailAddressUtil.isValid("\" \"@example.org")); Assert.assertTrue(EmailAddressUtil.isValid("\"john..doe\"@example.org")); Assert.assertTrue(EmailAddressUtil.isValid("mailhost!username@example.org")); Assert.assertTrue(EmailAddressUtil.isValid("user%example.com@example.org")); }
@Test public void invalidEmailAddresses() { Assert.assertFalse(EmailAddressUtil.isValid("Abc.example.com")); Assert.assertFalse(EmailAddressUtil.isValid("A@b@c@example.com")); Assert.assertFalse(EmailAddressUtil.isValid("a\"b(c)d,e:f;g<h>i[j\\k]l@example.com")); Assert.assertFalse(EmailAddressUtil.isValid("just\"not\"right@example.com")); Assert.assertFalse(EmailAddressUtil.isValid("this is\"not\\allowed@example.com")); Assert.assertFalse(EmailAddressUtil.isValid("this\\ still\\\"not\\\\allowed@example.com")); }