RepositoryUserProjectService implements PageableUserProjectService { @Override public Page<Project> getProjectsForUserPaginated(User user, Pageable pageable) { return projectRepo.findAll(getProjectSpecificationForUser(user), pageable); } @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 getProjectsForUserPaginatedReturnsLobDependentProjectsWhenUserIsNoManager() { var userLob = "LoB Test1234"; var pageable = PageRequest.of(0, 100); var expectedStatusSpecification = new ProjectSpecification(EXCLUDED_STATUS, LOB_DEPENDENT_STATUS, userLob); var expectedProjects = List.of(projectMock); var expectedPage = new PageImpl<>(expectedProjects); given(userServiceMock.getUserData(userMock)).willReturn(userDataMock); given(userDataMock.getLob()).willReturn(userLob); given(projectRepoMock.findAll(expectedStatusSpecification, pageable)).willReturn(expectedPage); var actualPage = userProjectService.getProjectsForUserPaginated(userMock, pageable); assertThat(actualPage).isEqualTo(expectedPage); }
@Test public void getProjectsForUserPaginatedReturnsAllProjectsWhenUserIsManager() { var pageable = PageRequest.of(0, 100); var expectedStatusSpecification = new ProjectSpecification(EXCLUDED_STATUS, Set.of(), null); var expectedProjects = List.of(projectMock); var expectedPage = new PageImpl<>(expectedProjects); given(userServiceMock.userIsManager(userMock)).willReturn(true); given(projectRepoMock.findAll(expectedStatusSpecification, pageable)).willReturn(expectedPage); var actualPage = userProjectService.getProjectsForUserPaginated(userMock, pageable); assertThat(actualPage).isEqualTo(expectedPage); }