WorkspacesImpl implements Workspaces { @Override public Workspace byName(String name) throws WorkspaceNotFoundException { List<Workspace> allWorkspaces = all(); for (Workspace workspace : allWorkspaces) { if (workspace.getName().equals(name)) { return workspace; } } throw new WorkspaceNotFoundException("Could not find workspace named '" + name + "'"); } WorkspacesImpl(Configuration conf, RestClient restClient); @Override List<Workspace> all(); @Override Workspace byName(String name); @Override Workspace current(); Workspaces using(Workspace currentWorkspace);  }
@Test(expected = WorkspaceNotFoundException.class) public void shouldNotFindFictionalWorkspace() throws Exception { String givenWorkspaceName = "no such workspace exists in kanbanery"; Workspace workspace = workspaces.byName(givenWorkspaceName); assertThat(workspace).isNotNull(); assertThat(workspace.getId()).isPositive(); assertThat(workspace.getName()).isEqualTo(givenWorkspaceName); }
@Test public void shouldFindByName() throws Exception { String givenWorkspaceName = TestConstants.EXISTING_WORKSPACE; Workspace workspace = workspaces.byName(givenWorkspaceName); assertThat(workspace).isNotNull(); assertThat(workspace.getId()).isPositive(); assertThat(workspace.getName()).isEqualTo(givenWorkspaceName); }