SonarConnection implements MetricCapability, TestCapability { @Override public String getMavenId(SoftwareProjectId softwareProjectId) throws ProjectNotFoundException, MavenIdNotFoundException { checkConnected(); checkSoftwareProjectId(softwareProjectId); try { String artifactId = softwareProjectId.getProjectId(); Resource resource = sonarClient.findResource(artifactId); return resource.getKey(); } catch (SonarResourceNotFoundException e) { throw new MavenIdNotFoundException("Can't get maven id of software project id: " + softwareProjectId, e); } } SonarConnection(); @Override void connect(String url, String login, String password); @Override Map<String, List<QualityMetric>> getMetricsByCategory(); @Override Map<SoftwareProjectId, String> listSoftwareProjectIds(); @Override void close(); @Override boolean equals(Object o); @Override int hashCode(); @Override String getDescription(SoftwareProjectId softwareProjectId); @Override SoftwareProjectId identify(ProjectKey projectKey); @Override TestResult analyzeUnitTests(SoftwareProjectId projectId); @Override TestResult analyzeIntegrationTests(SoftwareProjectId projectId); @Override QualityResult analyzeQuality(SoftwareProjectId projectId, String... metrics); @Override String getMavenId(SoftwareProjectId softwareProjectId); @Override String getName(SoftwareProjectId softwareProjectId); @Override boolean isClosed(); @Override boolean isProjectDisabled(SoftwareProjectId softwareProjectId); BuildTime getBuildTime(SoftwareProjectId softwareProjectId, Integer buildId); @Deprecated // NOT USED List<Integer> getBuildIds(SoftwareProjectId softwareProjectId); @Deprecated // NOT USED BuildState getBuildState(SoftwareProjectId softwareProjectId, Integer buildId); @Deprecated // NOT USED Date getEstimatedFinishTime(SoftwareProjectId softwareProjectId, Integer buildId); @Deprecated // NOT USED boolean isBuilding(SoftwareProjectId softwareProjectId, Integer buildId); @Deprecated // NOT USED int getLastBuildId(SoftwareProjectId softwareProjectId); @Deprecated // NOT USED List<Commiter> getBuildCommiters(SoftwareProjectId softwareProjectId, Integer buildId);  }
@Test public void should_get_maven_id() throws Exception { Resource resource = new Resource(); resource.setKey("artifactId"); when(sonarClient.findResource(anyString())).thenReturn(resource); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); String mavenId = sonar.getMavenId(softwareProjectId); assertEquals("artifactId", mavenId); }
@Test(expected = MavenIdNotFoundException.class) public void should_throw_exception_when_searching_maven_id_of_inexistant_project() throws Exception { Throwable notFound = new SonarResourceNotFoundException("not found"); when(sonarClient.findResource(anyString())).thenThrow(notFound); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); sonar.getMavenId(softwareProjectId); }