@Test public void getStatesByApplicationIdShouldReturnAListWithSingleElement() { given(applicationsRepository.findOne(FIRST_ID)).willReturn(firstApplicationEntity); given(statesHistoryRepository .findByApplicationEntityOrderByCreationDateDesc(firstApplicationEntity)) .willReturn(statesHistoryEntityListWithSingleElement); given(converterService .convert(statesHistoryEntityListWithSingleElement, StateHistoryDTO.class)) .willReturn(stateViewHistoryDTOListWithSingleElement); List<StateHistoryDTO> stateHistoryDTOList = statesHistoryService.getStateHistoriesByApplicationId(FIRST_ID); assertThat(stateHistoryDTOList, notNullValue()); assertThat(stateHistoryDTOList.isEmpty(), is(false)); assertThat(stateHistoryDTOList, equalTo(stateViewHistoryDTOListWithSingleElement)); then(applicationsRepository).should().findOne(FIRST_ID); then(statesHistoryRepository).should() .findByApplicationEntityOrderByCreationDateDesc(firstApplicationEntity); }
@Transactional(readOnly = true) @Override public List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId) { Assert.notNull(applicationId); ApplicationEntity applicationEntity = applicationsRepository.findOne(applicationId); Assert.notNull(applicationEntity); if (applicationEntity.isDeleted()) { return Collections.emptyList(); } List<StatesHistoryEntity> statesHistoryEntities = statesHistoryRepository.findByApplicationEntityOrderByCreationDateDesc(applicationEntity); return converterService.convert(statesHistoryEntities, StateHistoryDTO.class); }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional(readOnly = true) @Override public List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId) { Assert.notNull(applicationId); ApplicationEntity applicationEntity = applicationsRepository.findOne(applicationId); Assert.notNull(applicationEntity); if (applicationEntity.isDeleted()) { return Collections.emptyList(); } List<StatesHistoryEntity> statesHistoryEntities = statesHistoryRepository.findByApplicationEntityOrderByCreationDateDesc(applicationEntity); return converterService.convert(statesHistoryEntities, StateHistoryDTO.class); } }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional(readOnly = true) @Override public List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId) { Assert.notNull(applicationId); ApplicationEntity applicationEntity = applicationsRepository.findOne(applicationId); Assert.notNull(applicationEntity); if (applicationEntity.isDeleted()) { return Collections.emptyList(); } List<StatesHistoryEntity> statesHistoryEntities = statesHistoryRepository.findByApplicationEntityOrderByCreationDateDesc(applicationEntity); return converterService.convert(statesHistoryEntities, StateHistoryDTO.class); }  }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional(readOnly = true) @Override public List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId) { Assert.notNull(applicationId); ApplicationEntity applicationEntity = applicationsRepository.findOne(applicationId); Assert.notNull(applicationEntity); if (applicationEntity.isDeleted()) { return Collections.emptyList(); } List<StatesHistoryEntity> statesHistoryEntities = statesHistoryRepository.findByApplicationEntityOrderByCreationDateDesc(applicationEntity); return converterService.convert(statesHistoryEntities, StateHistoryDTO.class); }  @Transactional @Override void deleteStateHistoriesByApplication(ApplicationDTO applicationDTO); @Transactional @Override Long saveStateHistory(StateHistoryDTO state); @Transactional(readOnly = true) @Override List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId); }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional(readOnly = true) @Override public List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId) { Assert.notNull(applicationId); ApplicationEntity applicationEntity = applicationsRepository.findOne(applicationId); Assert.notNull(applicationEntity); if (applicationEntity.isDeleted()) { return Collections.emptyList(); } List<StatesHistoryEntity> statesHistoryEntities = statesHistoryRepository.findByApplicationEntityOrderByCreationDateDesc(applicationEntity); return converterService.convert(statesHistoryEntities, StateHistoryDTO.class); }  @Transactional @Override void deleteStateHistoriesByApplication(ApplicationDTO applicationDTO); @Transactional @Override Long saveStateHistory(StateHistoryDTO state); @Transactional(readOnly = true) @Override List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId);  }