### Question:
ValidationService implements Reloadable { public boolean isCountryAdmitted(String hostAddress) { if (settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST).isEmpty() && settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST).isEmpty()) { return true; } String countryCode = geoIpService.getCountryCode(hostAddress); boolean isCountryAllowed = validateWhitelistAndBlacklist(countryCode, ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST); ConsoleLogger.debug("Country code `{0}` for `{1}` is allowed: {2}", countryCode, hostAddress, isCountryAllowed); return isCountryAllowed; } 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 shouldNotInvokeGeoLiteApiIfCountryListsAreEmpty() { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); boolean result = validationService.isCountryAdmitted("addr"); assertThat(result, equalTo(true)); verifyZeroInteractions(geoIpService); }
@Test public void shouldAcceptCountryInWhitelist() { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "127.0.0.1"; given(geoIpService.getCountryCode(ip)).willReturn("CH"); boolean result = validationService.isCountryAdmitted(ip); assertThat(result, equalTo(true)); verify(geoIpService).getCountryCode(ip); }
@Test public void shouldRejectCountryMissingFromWhitelist() { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "123.45.67.89"; given(geoIpService.getCountryCode(ip)).willReturn("BR"); boolean result = validationService.isCountryAdmitted(ip); assertThat(result, equalTo(false)); verify(geoIpService).getCountryCode(ip); }
@Test public void shouldAcceptCountryAbsentFromBlacklist() { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "127.0.0.1"; given(geoIpService.getCountryCode(ip)).willReturn("BR"); boolean result = validationService.isCountryAdmitted(ip); assertThat(result, equalTo(true)); verify(geoIpService).getCountryCode(ip); }
@Test public void shouldRejectCountryInBlacklist() { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "123.45.67.89"; given(geoIpService.getCountryCode(ip)).willReturn("IT"); boolean result = validationService.isCountryAdmitted(ip); assertThat(result, equalTo(false)); verify(geoIpService).getCountryCode(ip); }