### Question:
OnJoinVerifier implements Reloadable { public void checkPlayerCountry(JoiningPlayer joiningPlayer, String address, boolean isAuthAvailable) throws FailedVerificationException { if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)) && settings.getProperty(ProtectionSettings.ENABLE_PROTECTION) && !permissionsManager.hasPermission(joiningPlayer, PlayerStatePermission.BYPASS_COUNTRY_CHECK) && !validationService.isCountryAdmitted(address)) { throw new FailedVerificationException(MessageKey.COUNTRY_BANNED_ERROR); } } OnJoinVerifier(); @PostConstruct @Override void reload(); void checkAntibot(JoiningPlayer joiningPlayer, boolean isAuthAvailable); void checkKickNonRegistered(boolean isAuthAvailable); void checkIsValidName(String name); boolean refusePlayerForFullServer(PlayerLoginEvent event); void checkNameCasing(String connectingName, PlayerAuth auth); void checkPlayerCountry(JoiningPlayer joiningPlayer, String address,
                                   boolean isAuthAvailable); void checkSingleSession(String name);  }### Answer:
@Test public void shouldNotCheckCountry() throws FailedVerificationException { JoiningPlayer joiningPlayer = JoiningPlayer.fromName("david"); String ip = "127.0.0.1"; given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(false); given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(true); onJoinVerifier.checkPlayerCountry(joiningPlayer, ip, false); verifyZeroInteractions(validationService); given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(false); onJoinVerifier.checkPlayerCountry(joiningPlayer, ip, true); verifyZeroInteractions(validationService); }
@Test public void shouldCheckAndAcceptUnregisteredPlayerCountry() throws FailedVerificationException { String ip = "192.168.0.1"; JoiningPlayer joiningPlayer = JoiningPlayer.fromName("lucas"); given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true); given(validationService.isCountryAdmitted(ip)).willReturn(true); onJoinVerifier.checkPlayerCountry(joiningPlayer, ip, false); verify(validationService).isCountryAdmitted(ip); }
@Test public void shouldCheckAndAcceptRegisteredPlayerCountry() throws FailedVerificationException { String ip = "192.168.10.24"; JoiningPlayer joiningPlayer = JoiningPlayer.fromName("gabriel"); given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true); given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(true); given(validationService.isCountryAdmitted(ip)).willReturn(true); onJoinVerifier.checkPlayerCountry(joiningPlayer, ip, true); verify(validationService).isCountryAdmitted(ip); }
@Test public void shouldThrowForBannedCountry() throws FailedVerificationException { String ip = "192.168.40.0"; JoiningPlayer joiningPlayer = JoiningPlayer.fromName("bob"); given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true); given(validationService.isCountryAdmitted(ip)).willReturn(false); expectValidationExceptionWith(MessageKey.COUNTRY_BANNED_ERROR); onJoinVerifier.checkPlayerCountry(joiningPlayer, ip, false); }