SonarConnection implements MetricCapability, TestCapability { @Override public QualityResult analyzeQuality(SoftwareProjectId projectId, String... metrics) { checkConnected(); checkSoftwareProjectId(projectId); if (metricsMap == null) { initializeMetrics(); } if (metrics.length == 0) { metrics = metricKeys; } QualityResult qualityResult = new QualityResult(); String artifactId = projectId.getProjectId(); if (!Strings.isNullOrEmpty(artifactId)) { for (String key : metrics) { addQualityMeasure(qualityResult, artifactId, key); } } return qualityResult; } 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_analyze_quality() throws SonarMeasureNotFoundException { SoftwareProjectId projectId = new SoftwareProjectId("artifactId"); Measure generatedLines = new Measure(); generatedLines.setValue(0D); when(sonarClient.findMeasure("artifactId", "coverage")).thenReturn(generatedLines); QualityResult result = sonar.analyzeQuality(projectId, "coverage"); assertNotNull(result.getMeasure("coverage")); }
@Test public void should_not_fail_if_quality_measures_are_not_found_for_analysis() throws SonarMeasureNotFoundException { SoftwareProjectId projectId = new SoftwareProjectId("artifactId"); when(sonarClient.findMeasure(anyString(), anyString())).thenThrow( new SonarMeasureNotFoundException("not found")); sonar.analyzeQuality(projectId); }