OrganizationHandler { public DbOrganization getOrganization(final String organizationId) { final DbOrganization dbOrganization = repositoryHandler.getOrganization(organizationId); if(dbOrganization == null){ throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) .entity("Organization " + organizationId + " does not exist.").build()); } return dbOrganization; } OrganizationHandler(final RepositoryHandler repositoryHandler); void store(final DbOrganization dbOrganization); List<String> getOrganizationNames(); DbOrganization getOrganization(final String organizationId); void deleteOrganization(final String organizationId); List<String> getCorporateGroupIds(final String organizationId); void addCorporateGroupId(final String organizationId, final String corporateGroupId); void removeCorporateGroupId(final String organizationId, final String corporateGroupId); DbOrganization getMatchingOrganization(final DbModule dbModule);  }
@Test public void getAnExistingOrganization(){ final DbOrganization organization = new DbOrganization(); organization.setName("test"); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getOrganization(organization.getName())).thenReturn(organization); final OrganizationHandler handler = new OrganizationHandler(repositoryHandler); final DbOrganization gotOrganization = handler.getOrganization(organization.getName()); assertNotNull(gotOrganization); assertEquals(organization, gotOrganization); verify(repositoryHandler, times(1)).getOrganization(organization.getName()); }
@Test public void getAnOrganizationThatDoesNotExist(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final OrganizationHandler handler = new OrganizationHandler(repositoryHandler); WebApplicationException exception = null; try { handler.getOrganization("doesNotExist"); }catch (WebApplicationException e){ exception = e; } assertNotNull(exception); Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), exception.getResponse().getStatus()); }