@Test public void shouldGetSupervisorForGivenSupervisoryNodeAndProgram() throws Exception { SupervisoryNode supervisoryNode = new SupervisoryNode(1L); Program program = new Program(2L); final User approver = new User(); List<User> listOfUsers = Arrays.asList(approver); when(userRepository.getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION)).thenReturn(listOfUsers); User actual = supervisoryNodeService.getApproverForGivenSupervisoryNodeAndProgram(supervisoryNode, program); verify(userRepository).getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION); assertThat(actual, is(approver)); }
public User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program) { List<User> users = userRepository.getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION); if (users.size() == 0) return null; return users.get(0); }
SupervisoryNodeService { public User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program) { List<User> users = userRepository.getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION); if (users.size() == 0) return null; return users.get(0); } }
SupervisoryNodeService { public User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program) { List<User> users = userRepository.getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION); if (users.size() == 0) return null; return users.get(0); }  }
SupervisoryNodeService { public User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program) { List<User> users = userRepository.getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION); if (users.size() == 0) return null; return users.get(0); }  @Autowired void setPageSize(@Value("${search.page.size}") String pageSize); void save(SupervisoryNode supervisoryNode); List<SupervisoryNode> getSupervisoryNodesBy(Integer page, String nameSearchCriteria, Boolean parent); List<SupervisoryNode> getAllSupervisoryNodesInHierarchyBy(Long userId, Long programId, String... rightNames); List<SupervisoryNode> getAllSupervisoryNodesInHierarchyBy(Long userId, String... rightNames); SupervisoryNode getFor(Facility facility, Program program); User getApproverFor(Facility facility, Program program); SupervisoryNode getParent(Long id); User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program); List<SupervisoryNode> getAll(); List<SupervisoryNode> getAllParentSupervisoryNodesInHierarchy(SupervisoryNode supervisoryNode); SupervisoryNode getByCode(SupervisoryNode supervisoryNode); Pagination getPagination(Integer page); Integer getTotalSearchResultCount(String param, Boolean parent); SupervisoryNode getSupervisoryNode(Long id); List<SupervisoryNode> getFilteredSupervisoryNodesByName(String param); List<SupervisoryNode> searchTopLevelSupervisoryNodesByName(String param); Long getTotalUnassignedSupervisoryNodeOfUserBy(Long userId, Long programId); }
SupervisoryNodeService { public User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program) { List<User> users = userRepository.getUsersWithRightInNodeForProgram(program, supervisoryNode, APPROVE_REQUISITION); if (users.size() == 0) return null; return users.get(0); }  @Autowired void setPageSize(@Value("${search.page.size}") String pageSize); void save(SupervisoryNode supervisoryNode); List<SupervisoryNode> getSupervisoryNodesBy(Integer page, String nameSearchCriteria, Boolean parent); List<SupervisoryNode> getAllSupervisoryNodesInHierarchyBy(Long userId, Long programId, String... rightNames); List<SupervisoryNode> getAllSupervisoryNodesInHierarchyBy(Long userId, String... rightNames); SupervisoryNode getFor(Facility facility, Program program); User getApproverFor(Facility facility, Program program); SupervisoryNode getParent(Long id); User getApproverForGivenSupervisoryNodeAndProgram(SupervisoryNode supervisoryNode, Program program); List<SupervisoryNode> getAll(); List<SupervisoryNode> getAllParentSupervisoryNodesInHierarchy(SupervisoryNode supervisoryNode); SupervisoryNode getByCode(SupervisoryNode supervisoryNode); Pagination getPagination(Integer page); Integer getTotalSearchResultCount(String param, Boolean parent); SupervisoryNode getSupervisoryNode(Long id); List<SupervisoryNode> getFilteredSupervisoryNodesByName(String param); List<SupervisoryNode> searchTopLevelSupervisoryNodesByName(String param); Long getTotalUnassignedSupervisoryNodeOfUserBy(Long userId, Long programId);  }