SessionUtil { public static String toStringGroupedByServer(Session session) { final Map<String, List<FileToOpen>> map = groupFilesByServer(session); return map.keySet() .stream() .sorted() .map(server -> String.format("%s:%n%s%n", server, map.get(server) .stream() .map(FileToOpen::getUri) .map(s -> " " + s) .collect(Collectors.joining("\n")))) .collect(Collectors.joining("\n")).trim(); }  static String toStringGroupedByServer(Session session); static void main(String[] args);  }
@Test public void testToStringGroupedByServer() 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); String expected = "local file:\n" + " file: "\n" + "server1.pl:\n" + " sftp: " sftp: "\n" + "server2.pl:\n" + " sftp: " sftp: "\n" + "server3:\n" + " sftp: final String actual = SessionUtil.toStringGroupedByServer(session).replaceAll("\r", ""); assertEquals(actual, expected); }
@Test public void testToStringGroupedByServerEmpty() throws Exception { final ArrayList<FileToOpen> filesToOpen = new ArrayList<>(); Session session = new Session("A", filesToOpen); final String actual = SessionUtil.toStringGroupedByServer(session); assertEquals(actual, ""); }