### Question:
Workspaces implements ListWorkspacesCommand.WorkspaceFactory { public boolean exists(String workspaceName) { if (!workspaces.containsKey(workspaceName)) { populateMapFromServer(); } return workspaces.containsKey(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 assertExistsWorkspace() throws Exception { when(server.execute(isA(Callable.class))).thenReturn(parse( "--------- -------------- -------- ----------------------------------------------------------------------------------------------------------\n" + "\n" + "name1 SND\\redsolo_cp COMPUTER\n")); Workspaces workspaces = new Workspaces(server); assertTrue("The workspace was reported as non existant", workspaces.exists(new Workspace("name1"))); }
@Test public void assertWorkspaceExistsWithOnlyName() throws Exception { when(server.execute(isA(Callable.class))).thenReturn(parse( "--------- -------------- -------- ----------------------------------------------------------------------------------------------------------\n" + "\n" + "name1 SND\\redsolo_cp COMPUTER\n")); Workspaces workspaces = new Workspaces(server); assertTrue("The workspace was reported as non existant", workspaces.exists("name1")); }
@Test public void assertUnknownWorkspaceDoesNotExists() throws Exception { when(server.execute(isA(Callable.class))).thenReturn(parse("")); Workspaces workspaces = new Workspaces(server); assertFalse("The unknown workspace was reported as existing", workspaces.exists(new Workspace("name1"))); }