HudsonConnection implements BuildCapability, ViewCapability, TestCapability { @Override public boolean isProjectDisabled(SoftwareProjectId softwareProjectId) throws ProjectNotFoundException { checkConnected(); checkSoftwareProjectId(softwareProjectId); try { String jobName = softwareProjectId.getProjectId(); HudsonJob job = hudson.findJob(jobName); return job.isDisabled(); } catch (HudsonJobNotFoundException e) { throw new ProjectNotFoundException("Can't find job with software project id: " + softwareProjectId, e); } }  @Override void connect(String url, String login, String password); @Override Map<SoftwareProjectId, String> listSoftwareProjectIds(); @Override Date getEstimatedFinishTime(SoftwareProjectId projectId, String buildId); @Override boolean isBuilding(SoftwareProjectId projectId, String buildId); @Override BuildState getBuildState(SoftwareProjectId projectId, String buildId); @Override String getLastBuildId(SoftwareProjectId projectId); @Override List<String> findViews(); @Override List<String> findProjectNamesByView(String viewName); @Override List<SoftwareProjectId> findSoftwareProjectIdsByViews(List<String> views); @Override void close(); @Override String getDescription(SoftwareProjectId projectId); @Override SoftwareProjectId identify(ProjectKey projectKey); @Override List<String> getBuildIds(SoftwareProjectId softwareProjectId); @Override String getMavenId(SoftwareProjectId softwareProjectId); @Override String getName(SoftwareProjectId softwareProjectId); @Override boolean isClosed(); @Override BuildTime getBuildTime(SoftwareProjectId softwareProjectId, String buildId); @Override boolean isProjectDisabled(SoftwareProjectId softwareProjectId); @Override List<Commiter> getBuildCommiters(SoftwareProjectId softwareProjectId, String buildId); @Override TestResult analyzeUnitTests(SoftwareProjectId softwareProjectId); @Override TestResult analyzeIntegrationTests(SoftwareProjectId softwareProjectId);  }
@Test public void should_get_a_disabled_project() throws Exception { HudsonJob job = new HudsonJob(); job.setDisabled(true); when(hudson.findJob(anyString())).thenReturn(job); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); boolean isDisabled = hudsonConnection.isProjectDisabled(softwareProjectId); assertTrue(isDisabled); }
@Test public void should_get_an_enabled_project() throws Exception { HudsonJob job = new HudsonJob(); job.setDisabled(false); when(hudson.findJob(anyString())).thenReturn(job); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); boolean isDisabled = hudsonConnection.isProjectDisabled(softwareProjectId); assertFalse(isDisabled); }
@Test(expected = ProjectNotFoundException.class) public void should_throw_exception_when_project_is_not_found() throws Exception { Throwable notFound = new HudsonJobNotFoundException("not found"); when(hudson.findJob(anyString())).thenThrow(notFound); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); hudsonConnection.isProjectDisabled(softwareProjectId); }