PositionServiceImpl extends AbstractLogicallyDeletableService<PositionDTO, PositionEntity> implements PositionService { @Transactional(readOnly = true) @Override public List<PositionDTO> getPositionsById(List<Long> ids) { Assert.notNull(ids); List<PositionEntity> positionEntities = positionRepository.findAll(ids); List<PositionDTO> emptyList = Collections.emptyList(); return positionEntities.isEmpty() ? emptyList : converterService.convert(positionEntities, PositionDTO.class); } @Autowired  PositionServiceImpl(PositionRepository positionRepository,
                             ConverterService converterService); @Transactional(readOnly = true) @Override List<PositionDTO> getPositionsById(List<Long> ids); @Transactional(readOnly = true) @Override PositionDTO getPositionDtoById(Long positionId); @Transactional(readOnly = true) @Override PositionDTO getPositionDtoByName(String positionName); @Transactional @Override Long saveOrUpdate(PositionDTO position);  }
@Test(expected = IllegalArgumentException.class) public void getPositionsByIdShouldThrowIllegalArgumentsExceptionWhenTheListOfIdsIsNull() { positionService.getPositionsById(null); }
@Test public void getPositionsByIdShouldReturnEmptyListWhenNoPositionsFoundWithTheGivenIds() { List<Long> ids = Arrays.asList(NON_EXISTENT_ID); given(positionRepository.findAll(ids)).willReturn(EMPTY_POSITION_ENTITY_LIST); List<PositionDTO> positionDTOs = positionService.getPositionsById(ids); assertTrue(positionDTOs.isEmpty()); }
@Test public void getPositionsByIdShouldReturnAListOfPositionsWhenThereArePositionsWithTheGivenId() { List<Long> ids = Arrays.asList(DEVELOPER_ID, DEVELOPER_ID, DEVELOPER_ID); given(positionRepository.findAll(ids)).willReturn(expectedPositionEntityList); given(converterService.convert(expectedPositionEntityList, PositionDTO.class)) .willReturn(expectedPositionDtoList); List<PositionDTO> actualPositionDtoList = positionService.getPositionsById(ids); assertEquals(actualPositionDtoList, expectedPositionDtoList); }