@Test public void testGetNominees() { List<Nominee> expectedNominees = seedHelper.getNominees(); doReturn(expectedNominees).when(nomineeRepository).findForCriteria(any(NomineeGetRequest.class)); doReturn(Arrays.asList(new User())).when(userService).getUsers(any(EmployeeCriteria.class), any(RequestInfo.class)); doNothing().when(employeeMapper).mapNominatingEmployeesWithNominees(anyListOf(Nominee.class), anyListOf(User.class)); List<Nominee> actualNominees = nomineeService.getNominees(new NomineeGetRequest(), new RequestInfo()); verify(nomineeRepository).findForCriteria(any(NomineeGetRequest.class)); verify(userService).getUsers(any(EmployeeCriteria.class), any(RequestInfo.class)); verify(employeeMapper).mapNominatingEmployeesWithNominees(anyListOf(Nominee.class), anyListOf(User.class)); assertEquals(expectedNominees, actualNominees); }
public List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo) { List<Nominee> nominees = nomineeRepository.findForCriteria(nomineeGetRequest); if (nominees.isEmpty()) return nominees; List<Long> ids = nominees.stream().map(nominee -> nominee.getEmployee().getId()).collect(Collectors.toList()); log.debug("NominatingEmployee ids " + ids); EmployeeCriteria employeeCriteria = EmployeeCriteria.builder() .id(ids).tenantId(nomineeGetRequest.getTenantId()).build(); List<User> users = userService.getUsers(employeeCriteria, requestInfo); log.debug("userService: " + users); nomineeNominatingEmployeeMapper.mapNominatingEmployeesWithNominees(nominees, users); nominees.forEach(nominee -> { List<EmployeeDocument> docs = documentsService.getDocumentsForReferenceType(nominee.getEmployee().getId(), nominee.getId(), EntityType.NOMINEE.toString(), nominee.getTenantId()); List<String> stringDocs = docs.stream().map(doc -> doc.getDocument()).collect(Collectors.toList()); nominee.setDocuments(stringDocs); }); return nominees; }
NomineeService { public List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo) { List<Nominee> nominees = nomineeRepository.findForCriteria(nomineeGetRequest); if (nominees.isEmpty()) return nominees; List<Long> ids = nominees.stream().map(nominee -> nominee.getEmployee().getId()).collect(Collectors.toList()); log.debug("NominatingEmployee ids " + ids); EmployeeCriteria employeeCriteria = EmployeeCriteria.builder() .id(ids).tenantId(nomineeGetRequest.getTenantId()).build(); List<User> users = userService.getUsers(employeeCriteria, requestInfo); log.debug("userService: " + users); nomineeNominatingEmployeeMapper.mapNominatingEmployeesWithNominees(nominees, users); nominees.forEach(nominee -> { List<EmployeeDocument> docs = documentsService.getDocumentsForReferenceType(nominee.getEmployee().getId(), nominee.getId(), EntityType.NOMINEE.toString(), nominee.getTenantId()); List<String> stringDocs = docs.stream().map(doc -> doc.getDocument()).collect(Collectors.toList()); nominee.setDocuments(stringDocs); }); return nominees; } }
NomineeService { public List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo) { List<Nominee> nominees = nomineeRepository.findForCriteria(nomineeGetRequest); if (nominees.isEmpty()) return nominees; List<Long> ids = nominees.stream().map(nominee -> nominee.getEmployee().getId()).collect(Collectors.toList()); log.debug("NominatingEmployee ids " + ids); EmployeeCriteria employeeCriteria = EmployeeCriteria.builder() .id(ids).tenantId(nomineeGetRequest.getTenantId()).build(); List<User> users = userService.getUsers(employeeCriteria, requestInfo); log.debug("userService: " + users); nomineeNominatingEmployeeMapper.mapNominatingEmployeesWithNominees(nominees, users); nominees.forEach(nominee -> { List<EmployeeDocument> docs = documentsService.getDocumentsForReferenceType(nominee.getEmployee().getId(), nominee.getId(), EntityType.NOMINEE.toString(), nominee.getTenantId()); List<String> stringDocs = docs.stream().map(doc -> doc.getDocument()).collect(Collectors.toList()); nominee.setDocuments(stringDocs); }); return nominees; }  }
NomineeService { public List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo) { List<Nominee> nominees = nomineeRepository.findForCriteria(nomineeGetRequest); if (nominees.isEmpty()) return nominees; List<Long> ids = nominees.stream().map(nominee -> nominee.getEmployee().getId()).collect(Collectors.toList()); log.debug("NominatingEmployee ids " + ids); EmployeeCriteria employeeCriteria = EmployeeCriteria.builder() .id(ids).tenantId(nomineeGetRequest.getTenantId()).build(); List<User> users = userService.getUsers(employeeCriteria, requestInfo); log.debug("userService: " + users); nomineeNominatingEmployeeMapper.mapNominatingEmployeesWithNominees(nominees, users); nominees.forEach(nominee -> { List<EmployeeDocument> docs = documentsService.getDocumentsForReferenceType(nominee.getEmployee().getId(), nominee.getId(), EntityType.NOMINEE.toString(), nominee.getTenantId()); List<String> stringDocs = docs.stream().map(doc -> doc.getDocument()).collect(Collectors.toList()); nominee.setDocuments(stringDocs); }); return nominees; }  List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo); List<Nominee> createAsync(NomineeRequest nomineeRequest); @Transactional void create(NomineeRequest nomineeRequest); List<Nominee> updateAsync(NomineeRequest nomineeRequest); @Transactional void update(NomineeRequest nomineeRequest); }
NomineeService { public List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo) { List<Nominee> nominees = nomineeRepository.findForCriteria(nomineeGetRequest); if (nominees.isEmpty()) return nominees; List<Long> ids = nominees.stream().map(nominee -> nominee.getEmployee().getId()).collect(Collectors.toList()); log.debug("NominatingEmployee ids " + ids); EmployeeCriteria employeeCriteria = EmployeeCriteria.builder() .id(ids).tenantId(nomineeGetRequest.getTenantId()).build(); List<User> users = userService.getUsers(employeeCriteria, requestInfo); log.debug("userService: " + users); nomineeNominatingEmployeeMapper.mapNominatingEmployeesWithNominees(nominees, users); nominees.forEach(nominee -> { List<EmployeeDocument> docs = documentsService.getDocumentsForReferenceType(nominee.getEmployee().getId(), nominee.getId(), EntityType.NOMINEE.toString(), nominee.getTenantId()); List<String> stringDocs = docs.stream().map(doc -> doc.getDocument()).collect(Collectors.toList()); nominee.setDocuments(stringDocs); }); return nominees; }  List<Nominee> getNominees(NomineeGetRequest nomineeGetRequest, RequestInfo requestInfo); List<Nominee> createAsync(NomineeRequest nomineeRequest); @Transactional void create(NomineeRequest nomineeRequest); List<Nominee> updateAsync(NomineeRequest nomineeRequest); @Transactional void update(NomineeRequest nomineeRequest);  }