PlayerService { public List<PlayerInfo> getPlayersGames() { List<PlayerInfo> result = new LinkedList<>(); for (Player player : players) { result.add(new PlayerInfo(player)); } List<String> savedList = saver.getSavedList(); for (String name : savedList) { boolean notFound = true; for (PlayerInfo player : result) { if (player.getName().equals(name)) { player.setSaved(true); notFound = false; } } if (notFound) { result.add(new PlayerInfo(name, true)); } } Collections.sort(result, new Comparator<PlayerInfo>() { @Override public int compare(PlayerInfo o1, PlayerInfo o2) { return o1.getName().compareTo(o2.getName()); } }); return result; }  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 shouldGetAllActivePlayersWithSavedGamesDataSortedByName() { createPlayer("activeSaved"); createPlayer("active"); when(saver.getSavedList()).thenReturn(Arrays.asList("activeSaved", "saved")); List<PlayerInfo> games = playerService.getPlayersGames(); assertEquals(3, games.size()); PlayerInfo active = games.get(0); PlayerInfo activeSaved = games.get(1); PlayerInfo saved = games.get(2); assertEquals("active", active.getName()); assertEquals("http: assertTrue(active.isActive()); assertFalse(active.isSaved()); assertEquals("activeSaved", activeSaved.getName()); assertEquals("http: assertTrue(activeSaved.isActive()); assertTrue(activeSaved.isSaved()); assertEquals("saved", saved.getName()); assertNull(saved.getCallbackUrl()); assertFalse(saved.isActive()); assertTrue(saved.isSaved()); }