### Question:
SaveServiceImpl implements SaveService { @Override public List<PlayerInfo> getSaves() { Map<String, PlayerInfo> map = new HashMap<>(); for (Player player : players.getAll()) { PlayerInfo info = new PlayerInfo(player); setDataFromRegistration(info, player.getId()); setSaveFromField(info, playerGames.get(player.getId())); map.put(player.getId(), info); } List<String> savedList = saver.getSavedList(); for (String id : savedList) { if (id == null) continue; boolean found = map.containsKey(id); if (found) { PlayerInfo info = map.get(id); info.setSaved(true); } else { PlayerSave save = saver.loadGame(id); PlayerInfo info = new PlayerInfo(save, null, null); setDataFromRegistration(info, id); map.put(id, info); } } List<PlayerInfo> result = new LinkedList<>(map.values()); Collections.sort(result, Comparator.comparing(playerInfo -> playerInfo.getId())); return result; }  @Override long saveAll(); @Override long saveAll(String roomName); @Override void loadAll(); @Override long save(String id); @Override boolean load(String id); @Override void load(String id, String roomName, String gameName, String save); @Override List<PlayerInfo> getSaves(); @Override void removeSave(String id); @Override void removeAllSaves(); static final String DEFAULT_CALLBACK_URL; }### Answer:
@Test public void shouldGetAllActivePlayersWithSavedGamesDataSortedByName() { Player activeSavedPlayer = createPlayer("activeSaved"); Player activePlayer = createPlayer("active"); scores(activeSavedPlayer, 10); scores(activePlayer, 11); PlayerSave save1 = new PlayerSave(activeSavedPlayer); PlayerSave save2 = new PlayerSave(activePlayer); PlayerSave save3 = new PlayerSave("saved", "http: when(saver.getSavedList()).thenReturn(Arrays.asList("activeSaved", "saved")); when(saver.loadGame("activeSaved")).thenReturn(save1); when(saver.loadGame("active")).thenReturn(save2); when(saver.loadGame("saved")).thenReturn(save3); fieldSave(0, "{'data':1}"); fieldSave(1, "{'data':2}"); createUser("activeSaved"); createUser("active"); createUser("saved"); List<PlayerInfo> games = saveService.getSaves(); assertEquals(3, games.size()); PlayerInfo active = games.get(0); PlayerInfo activeSaved = games.get(1); PlayerInfo saved = games.get(2); assertEquals("active", active.getId()); assertEquals("code_active", active.getCode()); assertEquals("readable_active", active.getReadableName()); assertEquals("http: assertEquals("game room", active.getGameName()); assertEquals("{\"data\":2}", active.getData()); assertEquals(11, active.getScore()); assertEquals("room", active.getRoomName()); assertEquals(true, active.isAiPlayer()); assertTrue(active.isActive()); assertFalse(active.isSaved()); assertEquals("activeSaved", activeSaved.getId()); assertEquals("code_activeSaved", activeSaved.getCode()); assertEquals("readable_activeSaved", activeSaved.getReadableName()); assertEquals("http: assertEquals("game room", activeSaved.getGameName()); assertEquals("{\"data\":1}", activeSaved.getData()); assertEquals(10, activeSaved.getScore()); assertEquals("room", activeSaved.getRoomName()); assertEquals(true, activeSaved.isAiPlayer()); assertTrue(activeSaved.isActive()); assertTrue(activeSaved.isSaved()); assertEquals("saved", saved.getId()); assertEquals("code_saved", saved.getCode()); assertEquals("readable_saved", saved.getReadableName()); assertEquals("http: assertEquals("saved game room", saved.getGameName()); assertNull(saved.getData()); assertEquals(15, saved.getScore()); assertEquals("room", saved.getRoomName()); assertEquals(false, saved.isAiPlayer()); assertFalse(saved.isActive()); assertTrue(saved.isSaved()); }