PlayerService { public Player findPlayerByIp(String ip) { lock.readLock().lock(); try { for (Player player : players) { if (player.getCallbackUrl().contains(ip)) { return player; } } return new NullPlayer(); } finally { lock.readLock().unlock(); } }  void savePlayerGame(String name); void loadPlayerGame(String name); Player addNewPlayer(final String name, final String callbackUrl, TContext context); void nextStepForAllGames(); void setSendScreenUpdates(boolean sendScreenUpdates); List<Player> getPlayers(); boolean alreadyRegistered(String playerName); Player findPlayer(String playerName); void updatePlayer(Player player); void updatePlayers(List<PlayerInfo> players); void clear(); Player findPlayerByIp(String ip); void removePlayerByIp(String ip); void removePlayerByName(String name); List<PlayerInfo> getPlayersGames();  }
@Test public void shouldFindPlayerWhenGetByIp() { Player newPlayer = createPlayer("vasya_ip"); Player player = playerService.findPlayerByIp("vasya_ip"); assertSame(newPlayer, player); }
@Test public void shouldGetNullPlayerWhenGetByNotExistsIp() { createPlayer("vasya_ip"); Player player = playerService.findPlayerByIp("kolia_ip"); assertEquals(NullPlayer.class, player.getClass()); }