### Question:
UserValidator implements Validator { public boolean isUserNameAsEmailValid(String username) { if (StringUtils.isBlank(username)) { return false; } Matcher matcher = EMAIL_PATTERN.matcher(username); return matcher.matches(); }  @Override boolean supports(Class<?> clazz); @Override void validate(Object obj, Errors errors); boolean isUserNameValid(String username); boolean isUserNameAsEmailValid(String username);  }### Answer:
@Test public void isUserNameAsEmailValid_shouldReturnFalseIfEmailInvalid() { String[] invalids = new String[] { "mkyong", "mkyong123@.com", "my@kong", "my.kong", "my.@kong", "@kong.my" }; for (String email : invalids) { Assert.assertFalse(validator.isUserNameAsEmailValid(email)); } }
@Test public void isUserNameAsEmailValid_shouldReturnTrueIfEmailValid() { String[] valids = new String[] { "mkyong@yahoo.com", "mkyong-100@yahoo.com", "mkyong.100@yahoo.com", "mkyong111@mkyong.com", "mkyong-100@mkyong.net", "mkyong.100@mkyong.com.au", "mkyong@1.com", "mkyong@gmail.com.com", "mk@t-yong.de" }; for (String email : valids) { Assert.assertTrue(validator.isUserNameAsEmailValid(email)); } }