@Test(expected = SonarProjectNotFoundException.class) public void should_throw_exception_when_project_is_not_found() throws Exception { Projects projects = new Projects(); when(genericSoftwareClient.resource(anyString(), eq(Projects.class), eq(MediaType.APPLICATION_XML_TYPE))) .thenReturn(projects); sonarClient.findProject(""); }
public Project findProject(String projectKey) throws SonarProjectNotFoundException { Preconditions.checkNotNull(projectKey, "projectKey is mandatory"); try { List<Project> projects = findProjects().getProjects(); for (Project project : projects) { if (project.getKey().equals(projectKey)) { return project; } } throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'"); } catch (SonarProjectsNotFoundException e) { throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'", e); } }
Sonar { public Project findProject(String projectKey) throws SonarProjectNotFoundException { Preconditions.checkNotNull(projectKey, "projectKey is mandatory"); try { List<Project> projects = findProjects().getProjects(); for (Project project : projects) { if (project.getKey().equals(projectKey)) { return project; } } throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'"); } catch (SonarProjectsNotFoundException e) { throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'", e); } } }
Sonar { public Project findProject(String projectKey) throws SonarProjectNotFoundException { Preconditions.checkNotNull(projectKey, "projectKey is mandatory"); try { List<Project> projects = findProjects().getProjects(); for (Project project : projects) { if (project.getKey().equals(projectKey)) { return project; } } throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'"); } catch (SonarProjectsNotFoundException e) { throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'", e); } } Sonar(String url);  Sonar(String url, String login, String password); }
Sonar { public Project findProject(String projectKey) throws SonarProjectNotFoundException { Preconditions.checkNotNull(projectKey, "projectKey is mandatory"); try { List<Project> projects = findProjects().getProjects(); for (Project project : projects) { if (project.getKey().equals(projectKey)) { return project; } } throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'"); } catch (SonarProjectsNotFoundException e) { throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'", 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); }
Sonar { public Project findProject(String projectKey) throws SonarProjectNotFoundException { Preconditions.checkNotNull(projectKey, "projectKey is mandatory"); try { List<Project> projects = findProjects().getProjects(); for (Project project : projects) { if (project.getKey().equals(projectKey)) { return project; } } throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'"); } catch (SonarProjectsNotFoundException e) { throw new SonarProjectNotFoundException("Can't find Sonar project with resourceId: '" + projectKey + "'", 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);  }