@Test public void project_found__but_uris_empty_updates_with_empty_list() { when(repository.findById("projectId")).thenReturn(Optional.of(project)); serviceToTest.updateProjectWhitelist("projectId", Collections.emptyList()); verify(repository).save(project); assertEquals(0,whitelist.size()); }
@UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); } }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }  }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }  @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) /* @formatter:on */ void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist); }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }  @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) /* @formatter:on */ void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist);  }