@Test public void getStateFlowDTOByFromStateDTOShouldReturnListWithSingleElementWhenStateDtoHasSingleStateFlow() { StateDTO stateDTO = StateDTO.builder().id(STATE_WITH_SINGLE_STATE_FLOW_ID).name( STATE_WITH_SINGLE_STATE_FLOW_NAME).build(); StatesEntity statesEntity = StatesEntity.builder().id(STATE_WITH_SINGLE_STATE_FLOW_ID) .name(STATE_WITH_SINGLE_STATE_FLOW_NAME).build(); StatesEntity stateEntityInStateFlowEntityList = StatesEntity.builder().id(FIRST_STATE_ID).name(FIRST_STATE_NAME).build(); StateDTO stateDTOInStateFlowDTOList = StateDTO.builder().id(FIRST_STATE_ID).name(FIRST_STATE_NAME).build(); List<StateFlowEntity> singleElementStateFlowEntityList = Collections.singletonList( StateFlowEntity.builder().fromStateEntity(statesEntity) .toStateEntity(stateEntityInStateFlowEntityList) .build() ); List<StateFlowDTO> expectedSingleElementStateFlowDtoList = Collections.singletonList( StateFlowDTO.builder().fromStateDTO(stateDTO).toStateDTO(stateDTOInStateFlowDTOList) .build() ); given(converterService.convert(stateDTO, StatesEntity.class)).willReturn(statesEntity); given(stateFlowRepository.findByFromStateEntity(statesEntity)) .willReturn(singleElementStateFlowEntityList); given(converterService.convert(singleElementStateFlowEntityList, StateFlowDTO.class)) .willReturn(expectedSingleElementStateFlowDtoList); Collection<StateFlowDTO> result = stateFlowService.getStateFlowDTOByFromStateDTO(stateDTO); assertThat(result, notNullValue()); assertThat(result, is(expectedSingleElementStateFlowDtoList)); then(converterService).should().convert(stateDTO, StatesEntity.class); then(stateFlowRepository).should().findByFromStateEntity(statesEntity); then(converterService).should().convert(singleElementStateFlowEntityList, StateFlowDTO.class); }
@Transactional(readOnly = true) @Override public Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO) { Assert.notNull(statesDTO); Assert.notNull(statesDTO.getId()); Assert.notNull(statesDTO.getName()); List<StateFlowEntity> stateFlowEntities = stateFlowRepository.findByFromStateEntity(converterService.convert(statesDTO, StatesEntity.class)); return converterService.convert(stateFlowEntities, StateFlowDTO.class); }
StateFlowServiceImpl implements StateFlowService { @Transactional(readOnly = true) @Override public Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO) { Assert.notNull(statesDTO); Assert.notNull(statesDTO.getId()); Assert.notNull(statesDTO.getName()); List<StateFlowEntity> stateFlowEntities = stateFlowRepository.findByFromStateEntity(converterService.convert(statesDTO, StatesEntity.class)); return converterService.convert(stateFlowEntities, StateFlowDTO.class); } }
StateFlowServiceImpl implements StateFlowService { @Transactional(readOnly = true) @Override public Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO) { Assert.notNull(statesDTO); Assert.notNull(statesDTO.getId()); Assert.notNull(statesDTO.getName()); List<StateFlowEntity> stateFlowEntities = stateFlowRepository.findByFromStateEntity(converterService.convert(statesDTO, StatesEntity.class)); return converterService.convert(stateFlowEntities, StateFlowDTO.class); }  }
StateFlowServiceImpl implements StateFlowService { @Transactional(readOnly = true) @Override public Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO) { Assert.notNull(statesDTO); Assert.notNull(statesDTO.getId()); Assert.notNull(statesDTO.getName()); List<StateFlowEntity> stateFlowEntities = stateFlowRepository.findByFromStateEntity(converterService.convert(statesDTO, StatesEntity.class)); return converterService.convert(stateFlowEntities, StateFlowDTO.class); }  @Transactional(readOnly = true) @Override Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO); }
StateFlowServiceImpl implements StateFlowService { @Transactional(readOnly = true) @Override public Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO) { Assert.notNull(statesDTO); Assert.notNull(statesDTO.getId()); Assert.notNull(statesDTO.getName()); List<StateFlowEntity> stateFlowEntities = stateFlowRepository.findByFromStateEntity(converterService.convert(statesDTO, StatesEntity.class)); return converterService.convert(stateFlowEntities, StateFlowDTO.class); }  @Transactional(readOnly = true) @Override Collection<StateFlowDTO> getStateFlowDTOByFromStateDTO(StateDTO statesDTO);  }