TeamCityConnection implements BuildCapability, TestCapability, ViewCapability { @Override public BuildTime getBuildTime(SoftwareProjectId softwareProjectId, String buildId) throws BuildNotFoundException, ProjectNotFoundException { checkConnected(); checkSoftwareProjectId(softwareProjectId); checkBuildId(buildId); try { String projectId = softwareProjectId.getProjectId(); TeamCityBuild teamcityBuild = teamCity.findBuild(projectId, buildId); return BuildTimes.createFrom(teamcityBuild); } catch (TeamCityBuildTypeNotFoundException e) { throw new ProjectNotFoundException("Cannot find build type with software project id:" + softwareProjectId, e); } catch (TeamCityBuildNotFoundException e) { throw new BuildNotFoundException("Cannot find build #" + buildId + " for software project id:" + softwareProjectId, e); } }  @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_get_build_time() throws Exception { TeamCityBuild build = new TeamCityBuild(); build.setStartDate("20110302T171940+0300"); build.setFinishDate("20110302T171941+0300"); when(teamCity.findBuild(anyString(), anyString())).thenReturn(build); BuildTime buildTime = teamCityConnection.getBuildTime(softwareProjectId(), "1"); assertEquals(1000, buildTime.getDuration()); assertNotNull(buildTime.getStartTime()); }