### Question:
Workspaces implements ListWorkspacesCommand.WorkspaceFactory { public Workspace getWorkspace(String workspaceName) { if (!workspaces.containsKey(workspaceName)) { populateMapFromServer(); } return workspaces.get(workspaceName); } Workspaces(Server server); Workspace getWorkspace(String workspaceName); boolean exists(String workspaceName); boolean exists(Workspace workspace); String getWorkspaceMapping(final String localPath); Workspace newWorkspace(final String workspaceName, final String serverPath, Collection<String> cloakedPaths, final String localPath); void deleteWorkspace(Workspace workspace); Workspace createWorkspace(String name, String computer, String owner, String comment);  }### Answer:
@Test public void assertListFromServerIsParsedProperly() throws Exception { when(server.execute(isA(Callable.class))).thenReturn(parse( "--------- -------------- -------- ----------------------------------------------------------------------------------------------------------\n" + "\n" + "name1 SND\\redsolo_cp COMPUTER\n")); Workspaces workspaces = new Workspaces(server); Workspace workspace = workspaces.getWorkspace("name1"); assertNotNull("Workspace was null", workspace); }
@Test public void assertListFromServerIsRetrievedOnce() throws Exception { when(server.execute(isA(Callable.class))).thenReturn(parse( "--------- -------------- -------- ----------------------------------------------------------------------------------------------------------\n" + "\n" + "name1 SND\\redsolo_cp COMPUTER\n")); Workspaces workspaces = new Workspaces(server); Workspace workspace = workspaces.getWorkspace("name1"); assertNotNull("Workspace was null", workspace); workspace = workspaces.getWorkspace("name1"); assertNotNull("Workspace was null", workspace); verify(server, times(1)).execute(isA(Callable.class)); }
@Test public void assertGetUnknownWorkspaceReturnsNull() throws Exception { when(server.execute(isA(Callable.class))).thenReturn(parse("")); Workspaces workspaces = new Workspaces(server); assertNull("The unknown workspace was not null", workspaces.getWorkspace("name1")); }