ApplicationsServiceImpl extends AbstractLogicallyDeletableService<ApplicationDTO, ApplicationEntity> implements ApplicationsService { @Transactional @Override public Long saveApplication(ApplicationDTO applicationDTO, StateHistoryDTO stateHistoryDTO) { Assert.notNull(stateHistoryDTO); Long applicationId = saveOrUpdate(applicationDTO); ApplicationEntity applicationEntity = applicationsRepository.findOne(applicationId); ApplicationDTO savedOrUpdatedApplicationDto = converterService.convert(applicationEntity, ApplicationDTO.class); stateHistoryDTO.setApplicationDTO(savedOrUpdatedApplicationDto); statesHistoryService.saveStateHistory(stateHistoryDTO); return savedOrUpdatedApplicationDto.getId(); } @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 public void saveApplicationShouldSaveAProperApplicationDTOAndStateDTO() { final StateHistoryDTO stateHistoryDTO = StateHistoryDTO.builder().channel(ChannelDTO.builder().id(8L).name(null).build()).candidateId(1L) .position(PositionDTO.builder().id(1L).name(null).build()).description("sss") .stateDTO(new StateDTO(1L, "newstate")).build(); given(converterService.convert(applicationDTO, ApplicationEntity.class)) .willReturn(applicationEntity); given(applicationsRepository.saveAndFlush(applicationEntity)) .willReturn(this.applicationEntity); given(converterService.convert(applicationEntity, ApplicationDTO.class)) .willReturn(applicationDTO); given(applicationsRepository.findOne(APPLICATION_ID)).willReturn(this.applicationEntity); Long result = applicationsService.saveApplication(applicationDTO, stateHistoryDTO); assertThat(result, notNullValue()); assertThat(result, equalTo(APPLICATION_ID)); assertThat(stateHistoryDTO.getApplicationDTO(), equalTo(applicationDTO)); then(converterService).should().convert(applicationDTO, ApplicationEntity.class); then(applicationsRepository).should().saveAndFlush(applicationEntity); then(converterService).should().convert(applicationEntity, ApplicationDTO.class); then(statesHistoryService).should().saveStateHistory(stateHistoryDTO); }
@Test(expected = IllegalArgumentException.class) public void saveApplicationWithApplicationDTONullShouldThrowIllegalArgumentException() { applicationsService.saveApplication(null, stateHistoryDTO); }
@Test(expected = IllegalArgumentException.class) public void saveApplicationWithStateDTONullShouldThrowIllegalArgumentException() { applicationsService.saveApplication(applicationDTO, null); }