StatesHistoryServiceImpl implements StatesHistoryService { @Transactional @Override public void deleteStateHistoriesByApplication(ApplicationDTO applicationDTO) { Assert.notNull(applicationDTO); Assert.notNull(applicationDTO.getId()); List<StatesHistoryEntity> statesHistoryEntities = statesHistoryRepository.findByApplicationEntityOrderByCreationDateDesc( applicationsRepository.findOne(applicationDTO.getId())); statesHistoryRepository.delete(statesHistoryEntities); }  @Transactional @Override void deleteStateHistoriesByApplication(ApplicationDTO applicationDTO); @Transactional @Override Long saveStateHistory(StateHistoryDTO state); @Transactional(readOnly = true) @Override List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId);  }
@Test(expected = IllegalArgumentException.class) public void deleteStateHistoriesByApplicationShouldThrowIllegalArgumentExceptionWhenTheGivenApplicationIsNull() { statesHistoryService.deleteStateHistoriesByApplication(null); }
@Test(expected = IllegalArgumentException.class) public void deleteStateHistoriesByApplicationShouldThrowIllegalArgumentExceptionWhenTheGivenApplicationsIdIsNull() { ApplicationDTO applicationDTO = ApplicationDTO.builder().id(null).build(); statesHistoryService.deleteStateHistoriesByApplication(applicationDTO); }
@Test public void deleteStateHistoriesByApplicationShouldDeleteTheCorrespondingStateHistories() { ApplicationDTO applicationDTO = ApplicationDTO.builder().id(FIRST_ID).build(); given(applicationsRepository.findOne(applicationDTO.getId())) .willReturn(firstApplicationEntity); given(statesHistoryRepository .findByApplicationEntityOrderByCreationDateDesc(firstApplicationEntity)) .willReturn(statesHistoryEntityListWithSingleElement); statesHistoryService.deleteStateHistoriesByApplication(applicationDTO); verify(statesHistoryRepository, atLeastOnce()).delete(statesHistoryEntityListWithSingleElement); }