Sonar { public Map<String, SonarQualityMetric> findMetrics() throws SonarMetricsNotFoundException { try { String metricUrl = sonarUrl + "/api/metrics?format=xml"; SonarMetrics sonarMetrics = client.resource(metricUrl, SonarMetrics.class); Map<String, SonarQualityMetric> qualityMetrics = new HashMap<String, SonarQualityMetric>(); for (SonarQualityMetric metric : sonarMetrics.metric) { qualityMetrics.put(metric.getKey(), metric); } return qualityMetrics; } catch (ResourceNotFoundException e) { throw new SonarMetricsNotFoundException("Can't find sonar metrics with Sonar: " + sonarUrl, e); } } 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 = SonarMetricsNotFoundException.class) public void should_throw_exception_if_sonar_metrics_are_not_found() throws Exception { Object call = genericSoftwareClient.resource(anyString(), any(Class.class)); when(call).thenThrow(new ResourceNotFoundException("not found")); sonarClient.findMetrics(); }