RepositoryUserProjectService implements PageableUserProjectService { @Override public Page<Project> searchProjectsForUserPaginated(String query, User user, Pageable pageable) { if(userService.userIsManager(user)) { return managerSearchService.searchProjects(query, pageable,null); } else { var userLob = userService.getUserData(user).getLob(); return staffSearchService.searchProjects(query, pageable, userLob); } } @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 searchProjectsForUserPaginatedSearchesInAllProjectsWhenUserIsManager() { var expectedQuery = "a cool query"; var expectedPageable = PageRequest.of(1, 4); given(userServiceMock.userIsManager(userMock)).willReturn(true); given(managerHibernateSearchServiceMock.searchProjects(expectedQuery, expectedPageable, null)) .willReturn(new PageImpl<>(List.of(projectMock))); var actualProjectPage = userProjectService.searchProjectsForUserPaginated(expectedQuery, userMock, expectedPageable); assertThat(actualProjectPage).containsExactly(projectMock); }
@Test public void searchProjectsForUserPaginatedSearchesInLobDependentProjectsWhenUserIsNoManager() { var expectedQuery = "a cool query"; var expectedLob = "LOB Test"; var expectedPageable = PageRequest.of(1, 4); given(userServiceMock.getUserData(userMock)).willReturn(userDataMock); given(userDataMock.getLob()).willReturn(expectedLob); given(staffHibernateSearchServiceMock.searchProjects(expectedQuery, expectedPageable, expectedLob)) .willReturn(new PageImpl<>(List.of(projectMock))); var actualProjectPage = userProjectService.searchProjectsForUserPaginated(expectedQuery, userMock, expectedPageable); assertThat(actualProjectPage).containsExactly(projectMock); }