SessionUtil { static Map<String, List<FileToOpen>> groupFilesByServer(Session session) { return session.getFilesToOpen() .stream() .collect(Collectors.groupingBy(FileToOpen::host)); }  static String toStringGroupedByServer(Session session); static void main(String[] args);  }
@Test public void testGroupFilesByServer() throws Exception { final ArrayList<FileToOpen> filesToOpen = new ArrayList<>(); filesToOpen.add(new FileToOpen("sftp: filesToOpen.add(new FileToOpen("sftp: filesToOpen.add(new FileToOpen("sftp: filesToOpen.add(new FileToOpen("sftp: filesToOpen.add(new FileToOpen("file: filesToOpen.add(new FileToOpen("sftp: Session session = new Session("A", filesToOpen); final Map<String, List<FileToOpen>> map = SessionUtil.groupFilesByServer(session); assertEquals(map.size(),4); assertTrue(map.containsKey("local file")); assertTrue(map.containsKey("server1.pl")); assertTrue(map.containsKey("server2.pl")); assertTrue(map.containsKey("server3.pl")); }
@Test public void testGroupFilesByServerEmpty() throws Exception { final ArrayList<FileToOpen> filesToOpen = new ArrayList<>(); Session session = new Session("A", filesToOpen); final Map<String, List<FileToOpen>> actual = SessionUtil.groupFilesByServer(session); assertEquals(actual, Collections.emptyMap()); }