RepositoryUserProjectService implements PageableUserProjectService { @Override public List<Project> getProjectsForUser(User user, Sort sort) { return projectRepo.findAll(getProjectSpecificationForUser(user), sort); } @Autowired  RepositoryUserProjectService(ProjectRepository projectRepo,
                                        UserService userService,
                                        @Qualifier("managerSearchService") HibernateSearchService managerSearchService,
                                        @Qualifier("staffSearchService") HibernateSearchService staffSearchService,
                                        ProjectBoardConfigurationProperties properties); @Override List<Project> getProjectsForUser(User user, Sort sort); @Override List<Project> searchProjectsForUser(User user, String query, Sort sort); @Override Page<Project> getProjectsForUserPaginated(User user, Pageable pageable); @Override Page<Project> searchProjectsForUserPaginated(String query, User user, Pageable pageable);  }
@Test public void getProjectsForUserReturnsLobDependentProjectsWhenUserIsNoManager() { var userLob = "LoB Test"; var expectedSpecification = new ProjectSpecification(EXCLUDED_STATUS, LOB_DEPENDENT_STATUS, userLob); var sort = Sort.unsorted(); var expectedProjects = List.of(projectMock); given(userServiceMock.getUserData(userMock)).willReturn(userDataMock); given(userDataMock.getLob()).willReturn(userLob); given(projectRepoMock.findAll(expectedSpecification, sort)).willReturn(expectedProjects); var actualProjects = userProjectService.getProjectsForUser(userMock, sort); assertThat(actualProjects).isEqualTo(expectedProjects); }
@Test public void getProjectsForUserReturnsAllProjectsWhenUserIsManager() { var expectedSpecification = new ProjectSpecification(EXCLUDED_STATUS, Set.of(), null); var sort = Sort.unsorted(); var expectedProjects = List.of(projectMock); given(userServiceMock.userIsManager(userMock)).willReturn(true); given(projectRepoMock.findAll(expectedSpecification, sort)).willReturn(expectedProjects); var actualProjects = userProjectService.getProjectsForUser(userMock, sort); assertThat(actualProjects).isEqualTo(expectedProjects); }