@Test public void getApplicationByCandidateIdShouldReturnThreeElementListOfApplicationDTOWhenCandidateIdExists() { final List<ApplicationEntity> applicationEntities = Arrays.asList(applicationEntity, applicationEntity, applicationEntity); final List<CandidateApplicationDTO> candidateApplicationDTOs = Arrays.asList(dummyCandidateApplicationDTO, dummyCandidateApplicationDTO, dummyCandidateApplicationDTO); given(candidateRepository.findOne(CANDIDATE_ID)).willReturn(candidateEntity); given(applicationsRepository.findByCandidateEntityAndDeletedFalse(candidateEntity, DEFAULT_PAGE_REQUEST)) .willReturn(new PageImpl<ApplicationEntity>(applicationEntities)); given(converterService.convert(applicationEntities, CandidateApplicationDTO.class)) .willReturn(candidateApplicationDTOs); final PagingResponse<CandidateApplicationDTO> result = applicationsService .getApplicationsByCandidateId(CANDIDATE_ID, PAGE_NUMBER_ZERO, PAGE_SIZE_TEN); assertThat(result.getTotal(), is(3L)); assertThat(result.getRows(), equalTo(candidateApplicationDTOs)); }
@Transactional(readOnly = true) @Override public PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId( Long candidateId, int page, int size) { Assert.notNull(candidateId); CandidateEntity candidateEntity = candidateRepository.findOne(candidateId); Pageable pageRequest = new PageRequest(page, size); final Page<ApplicationEntity> pageResult = applicationsRepository.findByCandidateEntityAndDeletedFalse(candidateEntity, pageRequest); List<CandidateApplicationDTO> candidateApplicationDTOs = converterService.convert(pageResult.getContent(), CandidateApplicationDTO.class); candidateApplicationDTOs = candidateApplicationDTOs.stream() .sorted((m1, m2) -> m2.getModificationDate().compareTo(m1.getModificationDate())) .collect(Collectors.toList()); return new PagingResponse<>(pageResult.getTotalElements(), candidateApplicationDTOs); }
ApplicationsServiceImpl extends AbstractLogicallyDeletableService<ApplicationDTO, ApplicationEntity> implements ApplicationsService { @Transactional(readOnly = true) @Override public PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId( Long candidateId, int page, int size) { Assert.notNull(candidateId); CandidateEntity candidateEntity = candidateRepository.findOne(candidateId); Pageable pageRequest = new PageRequest(page, size); final Page<ApplicationEntity> pageResult = applicationsRepository.findByCandidateEntityAndDeletedFalse(candidateEntity, pageRequest); List<CandidateApplicationDTO> candidateApplicationDTOs = converterService.convert(pageResult.getContent(), CandidateApplicationDTO.class); candidateApplicationDTOs = candidateApplicationDTOs.stream() .sorted((m1, m2) -> m2.getModificationDate().compareTo(m1.getModificationDate())) .collect(Collectors.toList()); return new PagingResponse<>(pageResult.getTotalElements(), candidateApplicationDTOs); } }
ApplicationsServiceImpl extends AbstractLogicallyDeletableService<ApplicationDTO, ApplicationEntity> implements ApplicationsService { @Transactional(readOnly = true) @Override public PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId( Long candidateId, int page, int size) { Assert.notNull(candidateId); CandidateEntity candidateEntity = candidateRepository.findOne(candidateId); Pageable pageRequest = new PageRequest(page, size); final Page<ApplicationEntity> pageResult = applicationsRepository.findByCandidateEntityAndDeletedFalse(candidateEntity, pageRequest); List<CandidateApplicationDTO> candidateApplicationDTOs = converterService.convert(pageResult.getContent(), CandidateApplicationDTO.class); candidateApplicationDTOs = candidateApplicationDTOs.stream() .sorted((m1, m2) -> m2.getModificationDate().compareTo(m1.getModificationDate())) .collect(Collectors.toList()); return new PagingResponse<>(pageResult.getTotalElements(), candidateApplicationDTOs); } @Autowired  ApplicationsServiceImpl(
      ApplicationsRepository applicationRepository,
      StatesHistoryService statesHistoryService,
      CandidateRepository candidateRepository,
      ConverterService converterService); }
ApplicationsServiceImpl extends AbstractLogicallyDeletableService<ApplicationDTO, ApplicationEntity> implements ApplicationsService { @Transactional(readOnly = true) @Override public PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId( Long candidateId, int page, int size) { Assert.notNull(candidateId); CandidateEntity candidateEntity = candidateRepository.findOne(candidateId); Pageable pageRequest = new PageRequest(page, size); final Page<ApplicationEntity> pageResult = applicationsRepository.findByCandidateEntityAndDeletedFalse(candidateEntity, pageRequest); List<CandidateApplicationDTO> candidateApplicationDTOs = converterService.convert(pageResult.getContent(), CandidateApplicationDTO.class); candidateApplicationDTOs = candidateApplicationDTOs.stream() .sorted((m1, m2) -> m2.getModificationDate().compareTo(m1.getModificationDate())) .collect(Collectors.toList()); return new PagingResponse<>(pageResult.getTotalElements(), candidateApplicationDTOs); } @Autowired  ApplicationsServiceImpl(
      ApplicationsRepository applicationRepository,
      StatesHistoryService statesHistoryService,
      CandidateRepository candidateRepository,
      ConverterService converterService); @Transactional(readOnly = true) @Override List<ApplicationDTO> getApplicationsByCandidateDTO(CandidateDTO candidateDTO); @Transactional(readOnly = true) @Override PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId(
      Long candidateId,
      int page,
      int size); @Transactional @Override void deleteApplicationsByCandidateDTO(CandidateDTO candidateDTO); @Transactional(readOnly = true) @Override ApplicationDTO getApplicationDtoById(Long applicationId); @Transactional @Override Long saveOrUpdate(ApplicationDTO applicationDTO); @Transactional @Override Long saveApplication(ApplicationDTO applicationDTO, StateHistoryDTO stateHistoryDTO); }
ApplicationsServiceImpl extends AbstractLogicallyDeletableService<ApplicationDTO, ApplicationEntity> implements ApplicationsService { @Transactional(readOnly = true) @Override public PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId( Long candidateId, int page, int size) { Assert.notNull(candidateId); CandidateEntity candidateEntity = candidateRepository.findOne(candidateId); Pageable pageRequest = new PageRequest(page, size); final Page<ApplicationEntity> pageResult = applicationsRepository.findByCandidateEntityAndDeletedFalse(candidateEntity, pageRequest); List<CandidateApplicationDTO> candidateApplicationDTOs = converterService.convert(pageResult.getContent(), CandidateApplicationDTO.class); candidateApplicationDTOs = candidateApplicationDTOs.stream() .sorted((m1, m2) -> m2.getModificationDate().compareTo(m1.getModificationDate())) .collect(Collectors.toList()); return new PagingResponse<>(pageResult.getTotalElements(), candidateApplicationDTOs); } @Autowired  ApplicationsServiceImpl(
      ApplicationsRepository applicationRepository,
      StatesHistoryService statesHistoryService,
      CandidateRepository candidateRepository,
      ConverterService converterService); @Transactional(readOnly = true) @Override List<ApplicationDTO> getApplicationsByCandidateDTO(CandidateDTO candidateDTO); @Transactional(readOnly = true) @Override PagingResponse<CandidateApplicationDTO> getApplicationsByCandidateId(
      Long candidateId,
      int page,
      int size); @Transactional @Override void deleteApplicationsByCandidateDTO(CandidateDTO candidateDTO); @Transactional(readOnly = true) @Override ApplicationDTO getApplicationDtoById(Long applicationId); @Transactional @Override Long saveOrUpdate(ApplicationDTO applicationDTO); @Transactional @Override Long saveApplication(ApplicationDTO applicationDTO, StateHistoryDTO stateHistoryDTO);  }