### Question:
ProjectServiceImpl implements ProjectService { @Override public ProjectAccessControl getProjectAccessControl(Project project){ List<UserTask> userTasks = modelService.getTasksBy(project, new ProcessModelType(), UserTask.class); Set<String> users = extractFromTasks(this::selectUsers, userTasks); Set<String> groups = extractFromTasks(this::selectGroups, userTasks); return new ProjectAccessControl(users, groups); } @Autowired  ProjectServiceImpl(ProjectRepository projectRepository,
                              ModelService modelService,
                              ModelTypeService modelTypeService,
                              JsonConverter<ProjectDescriptor> descriptorJsonConverter,
                              JsonConverter<Project> jsonConverter,
                              JsonConverter<Map> jsonMetadataConverter,
                              Set<ProjectValidator> projectValidators); @Override Page<Project> getProjects(Pageable pageable,
                                     String name); @Override Project createProject(Project project); @Override Project updateProject(Project projectToUpdate,
                                 Project newProject); @Override void deleteProject(Project project); @Override Optional<Project> findProjectById(String projectId); @Override FileContent exportProject(Project project); @Override ProjectAccessControl getProjectAccessControl(Project project); @Override Project importProject(MultipartFile file, @Nullable String name); @Override void validateProject(Project project);  }### Answer:
@Test public void should_getUsersAndGroupsBelongingToAProject_when_getProcessAccessControl() { List<UserTask> userTasks = asList(taskOne, taskTwo); when(taskOne.getCandidateGroups()).thenReturn(asList("groupOne", "groupTwo")); when(taskOne.getCandidateUsers()).thenReturn(asList("userOne", "userTwo")); when(taskTwo.getAssignee()).thenReturn("userThree"); when(modelService.getTasksBy(eq(project), any(ProcessModelType.class), eq(UserTask.class))) .thenReturn(userTasks); ProjectAccessControl projectAccessControl = projectService.getProjectAccessControl(project); assertThat(projectAccessControl.getGroups()) .hasSize(2) .contains("groupOne", "groupTwo"); assertThat(projectAccessControl.getUsers()) .hasSize(3) .contains("userOne", "userTwo", "userThree"); }
@Test public void should_getUsersAndGroupsBelongingToAProjectExludingExpressions_when_getProcessAccessControl() { List<UserTask> userTasks = asList(taskOne, taskTwo); when(taskOne.getCandidateGroups()).thenReturn(asList("groupOne", "${processsVariable.groupName}", "groupTwo")); when(taskOne.getCandidateUsers()).thenReturn(asList("${username_Var}", "userOne")); when(taskTwo.getAssignee()).thenReturn("${processsVariable.username}"); when(modelService.getTasksBy(eq(project), any(ProcessModelType.class), eq(UserTask.class))) .thenReturn(userTasks); ProjectAccessControl projectAccessControl = projectService.getProjectAccessControl(project); assertThat(projectAccessControl.getGroups()) .hasSize(2) .contains("groupOne", "groupTwo"); assertThat(projectAccessControl.getUsers()) .hasSize(1) .contains("userOne"); }
@Test public void should_returnEmptyLists_when_thereAreNotAssigneeAndCandidateUsersAndGroups() { List<UserTask> userTasks = asList(taskOne, taskTwo); when(taskOne.getCandidateGroups()).thenReturn(null); when(taskOne.getCandidateUsers()).thenReturn(null); when(taskTwo.getAssignee()).thenReturn(null); when(modelService.getTasksBy(eq(project), any(ProcessModelType.class), eq(UserTask.class))) .thenReturn(userTasks); ProjectAccessControl projectAccessControl = projectService.getProjectAccessControl(project); assertThat(projectAccessControl.getGroups()).isEmpty(); assertThat(projectAccessControl.getUsers()).isEmpty(); }
@Test public void should_returnEmptyLists_when_thereAreNotUserTasks() { List<UserTask> userTasks = new LinkedList<>(); when(modelService.getTasksBy(eq(project), any(ProcessModelType.class), eq(UserTask.class))) .thenReturn(userTasks); ProjectAccessControl projectAccessControl = projectService.getProjectAccessControl(project); assertThat(projectAccessControl.getGroups()).isEmpty(); assertThat(projectAccessControl.getUsers()).isEmpty(); }