RegularRegexCheckerImpl extends AbstractEmailChecker { @Override public boolean check(String email) { if (email == null) { return false; } if (StringUtils.isNotBlank(userDefinedRegex)) { Matcher matcher = Pattern.compile(userDefinedRegex).matcher(email); return matcher.matches(); } Matcher asciiMatcher = MATCH_ASCII_PATTERN.matcher(email); if (!asciiMatcher.matches()) { return false; } Matcher emailMatcher = EMAIL_PATTERN.matcher(email); if (!emailMatcher.matches()) { return false; } if (email.endsWith(".")) { return false; } return true; } RegularRegexCheckerImpl(String userDefined); @Override boolean check(String email);  }
@Test public void testCheck_valid() { regularCheck = new RegularRegexCheckerImpl(""); String email = "ab.c@yahoo.com"; boolean check = regularCheck.check(email); assertTrue(check); email = "_1ab.c@yahoo.com"; assertTrue(regularCheck.check(email)); email = "gégé@laposte.fr"; assertTrue(regularCheck.check(email)); }
@Test public void testCheck_Invalid() { regularCheck = new RegularRegexCheckerImpl(null); String email = ";-abc@yahoo.com."; boolean check = regularCheck.check(email); assertFalse(check); }