@Test public void searchProjectsForUserSearchesInAllProjectsWhenUserIsManager() { var expectedQuery = "a cool query"; given(userServiceMock.userIsManager(userMock)).willReturn(true); given(managerHibernateSearchServiceMock.searchProjects(expectedQuery, null)).willReturn(List.of(projectMock)); var actualProjects = userProjectService.searchProjectsForUser(userMock, expectedQuery, Sort.unsorted()); assertThat(actualProjects).containsExactly(projectMock); }
@Override public List<Project> searchProjectsForUser(User user, String query, Sort sort) { if(userService.userIsManager(user)) { return managerSearchService.searchProjects(query, null); } else { var userLob = userService.getUserData(user).getLob(); return staffSearchService.searchProjects(query, userLob); } }
RepositoryUserProjectService implements PageableUserProjectService { @Override public List<Project> searchProjectsForUser(User user, String query, Sort sort) { if(userService.userIsManager(user)) { return managerSearchService.searchProjects(query, null); } else { var userLob = userService.getUserData(user).getLob(); return staffSearchService.searchProjects(query, userLob); } } }
RepositoryUserProjectService implements PageableUserProjectService { @Override public List<Project> searchProjectsForUser(User user, String query, Sort sort) { if(userService.userIsManager(user)) { return managerSearchService.searchProjects(query, null); } else { var userLob = userService.getUserData(user).getLob(); return staffSearchService.searchProjects(query, userLob); } } @Autowired  RepositoryUserProjectService(ProjectRepository projectRepo,
                                        UserService userService,
                                        @Qualifier("managerSearchService") HibernateSearchService managerSearchService,
                                        @Qualifier("staffSearchService") HibernateSearchService staffSearchService,
                                        ProjectBoardConfigurationProperties properties); }
RepositoryUserProjectService implements PageableUserProjectService { @Override public List<Project> searchProjectsForUser(User user, String query, Sort sort) { if(userService.userIsManager(user)) { return managerSearchService.searchProjects(query, null); } else { var userLob = userService.getUserData(user).getLob(); return staffSearchService.searchProjects(query, 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); }
RepositoryUserProjectService implements PageableUserProjectService { @Override public List<Project> searchProjectsForUser(User user, String query, Sort sort) { if(userService.userIsManager(user)) { return managerSearchService.searchProjects(query, null); } else { var userLob = userService.getUserData(user).getLob(); return staffSearchService.searchProjects(query, 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);  }