TLDsCheckerImpl extends AbstractEmailChecker { @Override public boolean check(String email) { if (!isSelectBlackList) { return true; } if (email == null || email.indexOf('@') == -1) { return false; } String inputEmailTld = email.substring(email.lastIndexOf(".") + 1); if (tLDs != null && tLDs.contains(inputEmailTld.toUpperCase())) { return true; } return DomainValidator.getInstance(true).isValidTld(inputEmailTld); } TLDsCheckerImpl(List<String> tLDs, boolean isSelectBlackList); @Override boolean check(String email);  }
@Test public void testCheck_valid() { List<String> additionalTLDs = new ArrayList<String>(); additionalTLDs.add("xy1".toUpperCase()); tldCheck = new TLDsCheckerImpl(additionalTLDs, true); String email = "ab.c@sina.com.cn"; boolean check = tldCheck.check(email); Assert.assertTrue(check); email = "ab.c@sina.com.xy1"; check = tldCheck.check(email); Assert.assertTrue(check); }
@Test public void testCheck_invalid() { List<String> additionalTLDs = new ArrayList<String>(); additionalTLDs.add("abx".toUpperCase()); additionalTLDs.add("cde".toUpperCase()); additionalTLDs.add("xy1".toUpperCase()); tldCheck = new TLDsCheckerImpl(additionalTLDs, true); String email = "ab.c@sina.com.abx1"; boolean check = tldCheck.check(email); Assert.assertFalse(check); email = "ab.c@sina.com.xy"; check = tldCheck.check(email); Assert.assertFalse(check); }
@Test public void testCheck_null() { tldCheck = new TLDsCheckerImpl(null, true); String email = "ab.c@sina.com.abx1"; boolean check = tldCheck.check(email); Assert.assertFalse(check); email = "ab.c@sina.com.xy."; tldCheck = new TLDsCheckerImpl(new ArrayList<String>(), true); check = tldCheck.check(email); Assert.assertFalse(check); }