TeamCityConnection implements BuildCapability, TestCapability, ViewCapability { @Override public SoftwareProjectId identify(ProjectKey projectKey) throws ProjectNotFoundException { checkConnected(); Preconditions.checkNotNull(projectKey, "projectKey is mandatory"); try { String name = projectKey.getName(); List<TeamCityProject> projects = teamCity.findAllProjects(); for (TeamCityProject project : projects) { String projectName = project.getName(); if (projectName.equals(name)) { String projectId = project.getId(); return new SoftwareProjectId(projectId); } } } catch (TeamCityProjectsNotFoundException e) { throw new ProjectNotFoundException("Can't identify software project id with project key: " + projectKey, e); } throw new ProjectNotFoundException("Can't identify software project id with project key: " + projectKey); }  @Override void connect(String url, String login, String password); @Override void close(); @Override String getDescription(SoftwareProjectId softwareProjectId); @Override SoftwareProjectId identify(ProjectKey projectKey); @Override List<String> getBuildIds(SoftwareProjectId softwareProjectId); @Override Map<SoftwareProjectId, String> listSoftwareProjectIds(); @Override BuildState getBuildState(SoftwareProjectId softwareProjectId, String buildId); @Override Date getEstimatedFinishTime(SoftwareProjectId softwareProjectId, String buildId); @Override boolean isBuilding(SoftwareProjectId softwareProjectId, String buildId); @Override String getLastBuildId(SoftwareProjectId softwareProjectId); @Override String getMavenId(SoftwareProjectId softwareProjectId); @Override String getName(SoftwareProjectId softwareProjectId); @Override boolean isClosed(); @Override BuildTime getBuildTime(SoftwareProjectId softwareProjectId, String buildId); @Override boolean isProjectDisabled(SoftwareProjectId softwareProjectId); @Override List<Commiter> getBuildCommiters(SoftwareProjectId softwareProjectId, String buildId); @Override TestResult analyzeUnitTests(SoftwareProjectId softwareProjectId); @Override TestResult analyzeIntegrationTests(SoftwareProjectId softwareProjectId); @Override List<SoftwareProjectId> findSoftwareProjectIdsByViews(List<String> views); @Override List<String> findViews(); @Override List<String> findProjectNamesByView(String viewName);  }
@Test public void should_identify_project() throws Exception { addTwoProjects(); ProjectKey projectKey = new ProjectKey(); projectKey.setName("name1"); SoftwareProjectId softwareProjectId = teamCityConnection.identify(projectKey); assertEquals("id1", softwareProjectId.getProjectId()); }