### Question:
ListWorkspacesCommand extends AbstractCallableCommand<List<Workspace>, Exception> { static void log(final List<Workspace> workspaces, final PrintStream logger) { int maxName = "Workspace".length(); int maxOwner = "Owner".length(); int maxComputer = "Computer".length(); int maxComment = "Comment".length(); for (final Workspace workspace : workspaces) { final String name = workspace.getName(); maxName = Math.max(maxName, name.length()); final String ownerName = workspace.getOwner(); maxOwner = Math.max(maxOwner, ownerName.length()); final String computer = workspace.getComputer(); maxComputer = Math.max(maxComputer, computer.length()); final String comment = workspace.getComment(); maxComment = Math.max(maxComment, comment.length()); } final String template = "%1$-" + maxName + "s %2$-" + maxOwner + "s %3$-" + maxComputer + "s %4$-" + maxComment + "s"; final String header = String.format(template, "Workspace", "Owner", "Computer", "Comment"); logger.println(header); final String divider = String.format(template, StringUtils.repeat("-", maxName), StringUtils.repeat("-", maxOwner), StringUtils.repeat("-", maxComputer), StringUtils.repeat("-", maxComment)); logger.println(divider); for (final Workspace workspace : workspaces) { final String name = workspace.getName(); final String ownerName = workspace.getOwner(); final String computer = workspace.getComputer(); final String comment = workspace.getComment(); final String line = String.format(template, name, ownerName, computer, comment); logger.println(line); } } ListWorkspacesCommand(final ServerConfigurationProvider server);   ListWorkspacesCommand(final ServerConfigurationProvider server, final String computer, final boolean shouldLogWorkspaces); @Override Callable<List<Workspace>, Exception> getCallable(); List<Workspace> call(); List<Workspace> parse(Reader consoleReader);  }### Answer:
@Test public void logWithNoWorkspaces() throws IOException { ListWorkspacesCommand.log(new ArrayList<Workspace>(0), listener.getLogger()); assertLog( "Workspace Owner Computer Comment", "--------- ----- -------- -------" ); }
@Test public void logWithManyWorkspaces() throws IOException { final ArrayList<Workspace> workspaces = new ArrayList<Workspace>(); workspaces.add(new Workspace("Hudson.JOBXXXXXXXXXXXXXX", "XXXX-XXXX-007", "First.LastXX", "This is a comment")); workspaces.add(new Workspace("Hudson-newJob-MASTER", "COMPUTER", "jenkins-tfs-plugin", "Created by the Jenkins tfs-plugin functional tests.")); ListWorkspacesCommand.log(workspaces, listener.getLogger()); assertLog( "Workspace Owner Computer Comment ", "------------------------ ------------------ ------------- ---------------------------------------------------", "Hudson.JOBXXXXXXXXXXXXXX First.LastXX XXXX-XXXX-007 This is a comment ", "Hudson-newJob-MASTER jenkins-tfs-plugin COMPUTER Created by the Jenkins tfs-plugin functional tests." ); }
@Test public void logWithOneWorkspace() throws IOException { final ArrayList<Workspace> workspaces = new ArrayList<Workspace>(1); workspaces.add(new Workspace("asterix", "ASTERIX", "redsolo_cp", "This is a comment")); ListWorkspacesCommand.log(workspaces, listener.getLogger()); assertLog( "Workspace Owner Computer Comment ", "--------- ---------- -------- -----------------", "asterix redsolo_cp ASTERIX This is a comment" ); }