SonarConnection implements MetricCapability, TestCapability { @Override public TestResult analyzeUnitTests(SoftwareProjectId projectId) { checkConnected(); checkSoftwareProjectId(projectId); TestResult unitTestResult = new TestResult(); String artifactId = projectId.getProjectId(); if (Strings.isNullOrEmpty(artifactId)) { if (LOG.isDebugEnabled()) { LOG.debug("can't analyze project " + projectId + " without artifactId. Is it a maven project ?"); } } else { unitTestResult = createUnitTestAnalysis(artifactId); } return unitTestResult; } 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_build_valid_unit_test_result() throws SonarMeasureNotFoundException { Measure[] measures = new Measure[5]; for (Integer i = 0; i < measures.length; i++) { measures[i] = new Measure(); measures[i].setValue(i.doubleValue()); } when(sonarClient.findMeasure("artifactId", "coverage")).thenReturn(measures[0]); when(sonarClient.findMeasure("artifactId", "test_failures")).thenReturn(measures[1]); when(sonarClient.findMeasure("artifactId", "test_errors")).thenReturn(measures[2]); when(sonarClient.findMeasure("artifactId", "tests")).thenReturn(measures[3]); when(sonarClient.findMeasure("artifactId", "skipped_tests")).thenReturn(measures[4]); SoftwareProjectId projectId = new SoftwareProjectId("artifactId"); TestResult unitTestResult = sonar.analyzeUnitTests(projectId); assertEquals(0, unitTestResult.getCoverage(), 0); assertEquals(3, unitTestResult.getFailCount(), 0); assertEquals(4, unitTestResult.getSkipCount(), 0); assertEquals(0, unitTestResult.getPassCount(), 0); }