BambooConnection implements BuildCapability, TestCapability { @Override public boolean isProjectDisabled(SoftwareProjectId softwareProjectId) throws ProjectNotFoundException { checkConnected(); checkSoftwareProjectId(softwareProjectId); String planKey = softwareProjectId.getProjectId(); try { Plan plan = bamboo.findPlan(planKey); return !plan.isEnabled(); } catch (BambooPlanNotFoundException e) { throw new ProjectNotFoundException("Can't find plan with software project id: " + softwareProjectId, e); } }  @Override void connect(String url, String login, String password); @Override boolean isBuilding(SoftwareProjectId softwareProjectId, String buildId); @Override BuildState getBuildState(SoftwareProjectId projectId, String buildId); @Override String getLastBuildId(SoftwareProjectId projectId); @Override void close(); @Override String getDescription(SoftwareProjectId softwareProjectId); @Override SoftwareProjectId identify(ProjectKey projectKey); @Override Date getEstimatedFinishTime(SoftwareProjectId projectId, String buildId); @Override Map<SoftwareProjectId, String> listSoftwareProjectIds(); @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 projectId); @Override TestResult analyzeIntegrationTests(SoftwareProjectId projectId);  }
@Test public void should_get_a_disabled_project() throws Exception { Plan plan = new Plan(); plan.setEnabled(false); when(bamboo.findPlan(anyString())).thenReturn(plan); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); boolean isDisabled = bambooConnection.isProjectDisabled(softwareProjectId); assertTrue(isDisabled); }
@Test public void should_get_an_enabled_project() throws Exception { Plan plan = new Plan(); plan.setEnabled(true); when(bamboo.findPlan(anyString())).thenReturn(plan); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); boolean isDisabled = bambooConnection.isProjectDisabled(softwareProjectId); assertFalse(isDisabled); }
@Test(expected = ProjectNotFoundException.class) public void should_throw_exception_when_project_is_not_found() throws Exception { Throwable notFound = new BambooPlanNotFoundException("not found"); when(bamboo.findPlan(anyString())).thenThrow(notFound); SoftwareProjectId softwareProjectId = new SoftwareProjectId("projectId"); bambooConnection.isProjectDisabled(softwareProjectId); }