### Question:
AsynchronousLogin implements AsynchronousProcess { @VisibleForTesting boolean hasReachedMaxLoggedInPlayersForIp(Player player, String ip) { if (service.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP) <= 0 || service.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS) || "127.0.0.1".equalsIgnoreCase(ip) || "localhost".equalsIgnoreCase(ip)) { return false; } final String name = player.getName(); int count = 0; for (Player onlinePlayer : bukkitService.getOnlinePlayers()) { if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(onlinePlayer)) && !onlinePlayer.getName().equals(name) && dataSource.isLogged(onlinePlayer.getName().toLowerCase())) { ++count; } } return count >= service.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP); } AsynchronousLogin(); void login(Player player, String password); void forceLogin(Player player);  }### Answer:
@Test public void shouldPassMaxLoginPerIpCheck() { Player player = mockPlayer("Carl"); given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2); given(commonService.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(false); mockOnlinePlayersInBukkitService(); boolean result = asynchronousLogin.hasReachedMaxLoggedInPlayersForIp(player, "127.0.0.4"); assertThat(result, equalTo(false)); verify(commonService).hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS); verify(bukkitService).getOnlinePlayers(); }
@Test public void shouldSkipIpCheckForZeroThreshold() { Player player = mockPlayer("Fiona"); given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(0); boolean result = asynchronousLogin.hasReachedMaxLoggedInPlayersForIp(player, "192.168.0.1"); assertThat(result, equalTo(false)); verifyZeroInteractions(bukkitService); }
@Test public void shouldSkipIpCheckForPlayerWithMultipleAccountsPermission() { Player player = mockPlayer("Frank"); given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(1); given(commonService.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(true); boolean result = asynchronousLogin.hasReachedMaxLoggedInPlayersForIp(player, "127.0.0.4"); assertThat(result, equalTo(false)); verify(commonService).hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS); verifyZeroInteractions(bukkitService); }
@Test public void shouldFailIpCheckForIpWithTooManyPlayersOnline() { Player player = mockPlayer("Ian"); given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2); given(commonService.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(false); mockOnlinePlayersInBukkitService(); boolean result = asynchronousLogin.hasReachedMaxLoggedInPlayersForIp(player, "192.168.0.1"); assertThat(result, equalTo(true)); verify(commonService).hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS); verify(bukkitService).getOnlinePlayers(); }