LocalPartRegexCheckerImpl extends AbstractEmailChecker { @Override public boolean check(String email) { if (email == null || localpartPattern == null) { return false; } int pos = email.indexOf(Constant.AT); if (pos == -1) { return false; } String inputLocalPart = email.substring(0, pos); if (!localpartPattern.matcher(inputLocalPart).matches()) { return false; } return true; } LocalPartRegexCheckerImpl(String regex, boolean isShort, boolean isCaseSensitive); @Override boolean check(String email);  }
@Test public void testCheck_validate() { String regularPattern = "a9w"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email = "a1w@sina.com"; assertTrue(localPartCheck.check(email)); String email2 = "c1aw@sina.com"; assertTrue(localPartCheck.check(email2)); }
@Test public void testCheck_validate_translation() { String regularPattern = "*"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email = ";a9.w.-@sina.com"; assertFalse(localPartCheck.check(email)); assertTrue(localPartCheck.check("a@cc.com")); regularPattern = "a.9w9"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); email = "c.1de2@sina.com"; assertTrue(localPartCheck.check(email)); email = "c1de2.-@sina.com"; assertFalse(localPartCheck.check(email)); regularPattern = "a?9w"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); email = "c-3de@sina.com"; assertTrue(localPartCheck.check(email)); email = "c-3de-@sina.com"; assertFalse(localPartCheck.check(email)); regularPattern = "9a*"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); email = "6b8@qq.com"; assertTrue(email + " should match with " + regularPattern, localPartCheck.check(email)); email = "9a@qq.com"; assertTrue(email + " should match with " + regularPattern, localPartCheck.check(email)); email = "6b88uu@qq.com"; assertTrue(email + " should match with " + regularPattern, localPartCheck.check(email)); regularPattern = "9a?"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); email = "6b8@qq.com"; assertTrue(email + " should match with " + regularPattern, localPartCheck.check(email)); email = "9a@qq.com"; assertFalse(email + " should not match with " + regularPattern, localPartCheck.check(email)); email = "6b88uu@qq.com"; assertFalse(email + " should not match with " + regularPattern, localPartCheck.check(email)); }
@Test public void testCheck_invalid() { String regularPattern = "a1w"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email = "a_1bc@sina.com"; assertFalse(localPartCheck.check(email)); email = "c1-aw@sina.com"; assertFalse(localPartCheck.check(email)); }
@Test public void testCheck_valid_1() { String regularPattern = "a1w<talend.c>"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email = "a1wtalend.c@sina.com"; assertTrue(localPartCheck.check(email)); }
@Test public void testCheck_invalid_2() { String regularPattern = "a1w<talend.c>"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email2 = "c1aw@sina.com"; assertFalse(localPartCheck.check(email2)); }
@Test public void testCheck_invalid_null() { String regularPattern = "a1w"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email2 = null; assertFalse(localPartCheck.check(email2)); localPartCheck = new LocalPartRegexCheckerImpl(null, true, false); email2 = "c1aw@sina.com"; assertFalse(localPartCheck.check(email2)); }
@Test public void testCheck_casesenstive() { String regularPattern = "a9w"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, true); String email = "c2qw@sina.com"; assertTrue(localPartCheck.check(email)); regularPattern = "A9W"; localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, true); assertFalse(localPartCheck.check(email)); String email2 = "C2QW@sina.com"; assertTrue(localPartCheck.check(email2)); localPartCheck = new LocalPartRegexCheckerImpl(regularPattern, true, false); String email3 = "c2qw@sina.com"; assertTrue(localPartCheck.check(email2)); }