### Question:
ValidationService implements Reloadable { public boolean validateEmail(String email) { if (Utils.isEmailEmpty(email) || !StringUtils.isInsideString('@', email)) { return false; } final String emailDomain = email.split("@")[1]; return validateWhitelistAndBlacklist( emailDomain, EmailSettings.DOMAIN_WHITELIST, EmailSettings.DOMAIN_BLACKLIST); } ValidationService(); @PostConstruct @Override void reload(); ValidationResult validatePassword(String password, String username); boolean validateEmail(String email); boolean isEmailFreeForRegistration(String email, CommandSender sender); boolean isCountryAdmitted(String hostAddress); boolean isUnrestricted(String name); boolean fulfillsNameRestrictions(Player player);  }### Answer:
@Test public void shouldAcceptEmailWithEmptyLists() { given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)).willReturn(Collections.emptyList()); boolean result = validationService.validateEmail("test@example.org"); assertThat(result, equalTo(true)); }
@Test public void shouldAcceptEmailWithWhitelist() { given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)) .willReturn(asList("domain.tld", "example.com")); given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)).willReturn(Collections.emptyList()); boolean result = validationService.validateEmail("TesT@Example.com"); assertThat(result, equalTo(true)); }
@Test public void shouldRejectEmailNotInWhitelist() { given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)) .willReturn(asList("domain.tld", "example.com")); given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)).willReturn(Collections.emptyList()); boolean result = validationService.validateEmail("email@other-domain.abc"); assertThat(result, equalTo(false)); }
@Test public void shouldAcceptEmailNotInBlacklist() { given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)) .willReturn(asList("Example.org", "a-test-name.tld")); boolean result = validationService.validateEmail("sample@valid-name.tld"); assertThat(result, equalTo(true)); }
@Test public void shouldRejectEmailInBlacklist() { given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)) .willReturn(asList("Example.org", "a-test-name.tld")); boolean result = validationService.validateEmail("sample@a-Test-name.tld"); assertThat(result, equalTo(false)); }
@Test public void shouldRejectInvalidEmail() { assertThat(validationService.validateEmail("invalidinput"), equalTo(false)); }
@Test public void shouldRejectInvalidEmailWithoutDomain() { assertThat(validationService.validateEmail("invalidinput@"), equalTo(false)); }
@Test public void shouldRejectDefaultEmail() { assertThat(validationService.validateEmail("your@email.com"), equalTo(false)); }