Sonar { public Measure findMeasure(String artifactId, String measureKey) throws SonarMeasureNotFoundException { Preconditions.checkArgument(!Strings.isNullOrEmpty(artifactId), "artifactId is a mandatory parameter"); Preconditions.checkNotNull(measureKey, "measureKey is a mandatory parameter"); return findMeasureFromSonar(artifactId, measureKey); } Sonar(String url);  Sonar(String url, String login, String password); Measure findMeasure(String artifactId, String measureKey); Resource findResource(String resourceId); Map<String, SonarQualityMetric> findMetrics(); Projects findProjects(); Project findProject(String projectKey);  }
@Test(expected = SonarMeasureNotFoundException.class) public void should_throw_exception_when_sonar_connection_fails() throws SonarMeasureNotFoundException { when(sonar.find(Mockito.any(ResourceQuery.class))).thenThrow(new ConnectionException()); sonarClient.findMeasure("artifactId", "measureKey"); }
@Test(expected = SonarMeasureNotFoundException.class) public void should_throw_exception_when_resource_is_not_fond() throws SonarMeasureNotFoundException { when(sonar.find(Mockito.any(ResourceQuery.class))).thenReturn(null); sonarClient.findMeasure("artifactId", "measureKey"); }
@Test(expected = IllegalArgumentException.class) public void should_throw_exception_when_artifact_id_is_empty() throws SonarMeasureNotFoundException { sonarClient.findMeasure("", "measureKey"); }
@Test(expected = SonarMeasureNotFoundException.class) public void should_throw_exception_when_measure_is_not_found() throws Exception { sonarClient.findMeasure("artifactId", "measureKey"); }