### Question:
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);  }### Answer:
@Test public void project_not_found_throws_not_found_exception() { expectedException.expect(NotFoundException.class); when(repository.findById("projectId")).thenReturn(Optional.empty()); serviceToTest.updateProjectWhitelist("projectId", null); }
@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()); }
@Test public void project_found__and_2_uris_contained_updates_to_those_uris() throws Exception{ URI uri1 = new URI("http: URI uri2 = new URI("http: when(repository.findById("projectId")).thenReturn(Optional.of(project)); List<URI> uris = Arrays.asList(uri1,uri2); serviceToTest.updateProjectWhitelist("projectId", uris); verify(repository).save(project); assertEquals(2,whitelist.size()); assertTrue(whitelist.contains(uri1)); assertTrue(whitelist.contains(uri2)); }