### Question:
ListWorkspacesCommand extends AbstractCallableCommand<List<Workspace>, Exception> { public List<Workspace> parse(Reader consoleReader) throws IOException { List<Workspace> list = new ArrayList<Workspace>(); TextTableParser parser = new TextTableParser(consoleReader, 1); while (parser.nextRow()) { Workspace workspace = new Workspace( parser.getColumn(0), parser.getColumn(2), parser.getColumn(1), Util.fixNull(parser.getColumn(3))); list.add(workspace); } return list; } 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 assertEmptyListWithEmptyOutput() throws Exception { ListWorkspacesCommand command = new ListWorkspacesCommand(mock(Server.class)); List<Workspace> list = command.parse(new StringReader("")); assertNotNull("List can not be null", list); assertEquals("Number of workspaces was incorrect", 0, list.size()); }
@Test public void assertListWithValidOutput() throws Exception { StringReader reader = new StringReader( "Server: https: "Workspace Owner Computer Comment\n" + "--------- -------------- -------- ----------------------------------------------------------------------------------------------------------\n" + "\n" + "asterix2 SND\\redsolo_cp ASTERIX\n" + "astreix SND\\redsolo_cp ASTERIX This is a comment\n"); ListWorkspacesCommand command = new ListWorkspacesCommand( mock(Server.class)); List<Workspace> list = command.parse(reader); assertNotNull("List can not be null", list); assertEquals("Number of workspaces was incorrect", 2, list.size()); Workspace workspace = list.get(0); assertEquals("The workspace name is incorrect", "asterix2", workspace.getName()); assertEquals("The owner name is incorrect", "SND\\redsolo_cp", workspace.getOwner()); assertEquals("The computer name is incorrect", "ASTERIX", workspace.getComputer()); workspace = list.get(1); assertEquals("The workspace name is incorrect", "astreix", workspace.getName()); assertEquals("The owner name is incorrect", "SND\\redsolo_cp", workspace.getOwner()); assertEquals("The computer name is incorrect", "ASTERIX", workspace.getComputer()); assertEquals("The comment is incorrect", "This is a comment", workspace.getComment()); }
@Test public void assertListWithWorkspaceContainingSpace() throws Exception { StringReader reader = new StringReader( "Server: https: "Workspace Owner Computer Comment\n" + "------------------ ---------- -------- ----------------------------------------\n" + "Hudson-node lookup redsolo_cp ASTERIX\n"); ListWorkspacesCommand command = new ListWorkspacesCommand( mock(Server.class)); List<Workspace> list = command.parse(reader); assertNotNull("List can not be null", list); assertEquals("Number of workspaces was incorrect", 1, list.size()); Workspace workspace = list.get(0); assertEquals("The workspace name is incorrect", "Hudson-node lookup", workspace.getName()); }
@Bug(4666) @Test public void assertNoIndexOutOfBoundsIsThrown() throws Exception { StringReader reader = new StringReader( "Server: teamserver-01\n" + "Workspace Owner Computer Comment\n" + "----------------- ------ ----------- ------------------------------------------\n" + "Hudson-Scrumboard dennis W7-DENNIS-1\n" + "W7-DENNIS-1 dennis W7-DENNIS-1\n"); new ListWorkspacesCommand(mock(Server.class)).parse(reader); }
@Bug(4726) @Test public void assertNoIndexOutOfBoundsIsThrownSecondEdition() throws Exception { StringReader reader = new StringReader( "Server: xxxx-xxxx-010\n" + "Workspace Owner Computer Comment\n" + "------------------------ ------------ ------------- ---------------------------\n" + "Hudson.JOBXXXXXXXXXXXXXX First.LastXX XXXX-XXXX-007\n"); new ListWorkspacesCommand(mock(Server.class)).parse(reader); }