Problem4_1 { public static List<List<Player>> teams(List<Player> players) { List<Player> sorted = players.stream().sorted((p1, p2) -> p1.rating - p2.rating).collect(Collectors.toList()); int totalPlayers = players.size(); return Arrays.asList(sorted.subList(0, totalPlayers / 2), sorted.subList(totalPlayers / 2, totalPlayers)); }  static List<List<Player>> teams(List<Player> players);  }
@Test public void shouldDistributePlayersIntoTwoUnfairTeams() throws Exception { List<Player> players = Arrays.asList(new Player("a", 10), new Player("b", 7), new Player("c", 11), new Player("d", 2), new Player("e", 4), new Player("f", 15)); List<List<Player>> teams = Problem4_1.teams(players); assertThat(teams.get(0), CoreMatchers.equalTo(Arrays.asList(new Player("d", 2), new Player("e", 4), new Player("b", 7)))); assertThat(teams.get(1), CoreMatchers.equalTo(Arrays.asList(new Player("a", 10), new Player("c", 11), new Player("f", 15)))); }