ApplicationsServiceImpl extends AbstractLogicallyDeletableService<ApplicationDTO, ApplicationEntity> implements ApplicationsService { @Transactional(readOnly = true) @Override public List<ApplicationDTO> getApplicationsByCandidateDTO(CandidateDTO candidateDTO) { Assert.notNull(candidateDTO); Assert.notNull(candidateDTO.getId()); CandidateEntity candidateEntity = candidateRepository.findOne(candidateDTO.getId()); List<ApplicationEntity> applicationEntities = applicationsRepository.findByCandidateEntity(candidateEntity); return converterService.convert(applicationEntities, ApplicationDTO.class); } @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);  }
@Test(expected = IllegalArgumentException.class) public void getApplicationsByCandidateDTOShouldThrowIllegalArgumentExceptionWhenCandidateDTOIsNull() { applicationsService.getApplicationsByCandidateDTO(null); }
@Test(expected = IllegalArgumentException.class) public void getApplicationsByCandidateDTOShouldThrowIllegalArgumentExceptionWhenCandidateDTOsIdIsNull() { CandidateDTO candidateDTO = CandidateDTO.builder().id(null).build(); applicationsService.getApplicationsByCandidateDTO(candidateDTO); }
@Test public void getApplicationByCandidateDTOShouldReturnEmptyListWhenCandidateIdIsNotFound() { CandidateDTO candidateDTO = CandidateDTO.builder().id(NON_EXISTENT_CANDIDATE_ID).build(); given(candidateRepository.findOne(NON_EXISTENT_CANDIDATE_ID)).willReturn(null); given(applicationsRepository.findByCandidateEntity(null)).willReturn(Collections.emptyList()); List<ApplicationDTO> result = applicationsService.getApplicationsByCandidateDTO(candidateDTO); assertTrue(result.isEmpty()); }
@Test public void getApplicationByCandidateDTOShouldReturnOneElementListOfApplicationDTOWhenCandidateIdExists() { CandidateDTO candidateDTO = CandidateDTO.builder().id(CANDIDATE_ID).build(); List<ApplicationEntity> applicationEntities = Collections.singletonList(applicationEntity); List<ApplicationDTO> applicationDTOs = Collections.singletonList(applicationDTO); given(candidateRepository.findOne(CANDIDATE_ID)).willReturn(candidateEntity); given(applicationsRepository.findByCandidateEntity(candidateEntity)) .willReturn(applicationEntities); given(converterService.convert(applicationEntities, ApplicationDTO.class)) .willReturn(applicationDTOs); List<ApplicationDTO> result = applicationsService.getApplicationsByCandidateDTO(candidateDTO); assertThat(result, equalTo(applicationDTOs)); }
@Test public void getApplicationByCandidateDTOShouldReturnThreeElementListOfApplicationDTOWhenCandidateIdExists() { CandidateDTO candidateDTO = CandidateDTO.builder().id(CANDIDATE_ID).build(); List<ApplicationEntity> applicationEntities = Arrays.asList(applicationEntity, applicationEntity, applicationEntity); List<ApplicationDTO> applicationDTOs = Arrays.asList(applicationDTO, applicationDTO, applicationDTO); given(candidateRepository.findOne(CANDIDATE_ID)).willReturn(candidateEntity); given(applicationsRepository.findByCandidateEntity(candidateEntity)) .willReturn(applicationEntities); given(converterService.convert(applicationEntities, ApplicationDTO.class)) .willReturn(applicationDTOs); List<ApplicationDTO> result = applicationsService.getApplicationsByCandidateDTO(candidateDTO); assertThat(result, equalTo(applicationDTOs)); }