OrganizationHandler { public DbOrganization getMatchingOrganization(final DbModule dbModule) { if(dbModule.getOrganization() != null && !dbModule.getOrganization().isEmpty()){ return getOrganization(dbModule.getOrganization()); } for(final DbOrganization organization: repositoryHandler.getAllOrganizations()){ final CorporateFilter corporateFilter = new CorporateFilter(organization); if(corporateFilter.matches(dbModule)){ return organization; } } return null; } 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 getMatchingOrganizationOfAModule(){ final DbModule module = new DbModule(); final DbArtifact artifact = new DbArtifact(); artifact.setGroupId(GrapesTestUtils.CORPORATE_GROUPID_4TEST); module.addArtifact(artifact); final RepositoryHandler repositoryHandler = GrapesTestUtils.getRepoHandlerMock(); final OrganizationHandler handler = new OrganizationHandler(repositoryHandler); final DbOrganization gotOrganization = handler.getMatchingOrganization(module); verify(repositoryHandler, times(1)).getAllOrganizations(); assertEquals(GrapesTestUtils.ORGANIZATION_NAME_4TEST, gotOrganization.getName()); }
@Test public void getMatchingOrganizationOfAModuleWhenThereIsNone(){ final DbModule module = new DbModule(); final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("unknown.production"); module.addArtifact(artifact); final RepositoryHandler repositoryHandler = GrapesTestUtils.getRepoHandlerMock(); final OrganizationHandler handler = new OrganizationHandler(repositoryHandler); final DbOrganization organization = handler.getMatchingOrganization(new DbModule()); assertNull(organization); }