Sonar { public Resource findResource(String resourceId) throws SonarResourceNotFoundException { Preconditions.checkNotNull(resourceId, "resourceId is mandatory"); ResourceQuery query = new ResourceQuery(resourceId); try { Resource resource = sonar.find(query); if (resource == null) { throw new SonarResourceNotFoundException("Resource " + resourceId + " not found in Sonar " + sonarUrl); } return resource; } catch (ConnectionException e) { throw new SonarResourceNotFoundException("Resource " + resourceId + " not found in 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 = SonarResourceNotFoundException.class) public void should_throw_exception_when_resource_is_not_found() throws Exception { sonarClient.findResource("resourceId"); }
@Test(expected = SonarResourceNotFoundException.class) public void should_throw_exception_when_connection_exception() throws Exception { when(sonar.find(any(ResourceQuery.class))).thenThrow(new ConnectionException()); sonarClient.findResource("resourceId"); }