@Test public void getChannelDtoByNameShouldReturnExistingChannelDtoWhenChannelNameIsExisting() { // Given given(channelRepository.findByName(CHANNEL_NAME_FACEBOOK)).willReturn(facebookEntity); given(converterService.convert(facebookEntity, ChannelDTO.class)).willReturn(facebookDto); // When ChannelDTO channelDTO = channelService.getChannelDtoByName(CHANNEL_NAME_FACEBOOK); // Then assertThat(channelDTO, notNullValue()); assertThat(channelDTO, equalTo(facebookDto)); then(channelRepository).should().findByName(CHANNEL_NAME_FACEBOOK); then(converterService).should().convert(facebookEntity, ChannelDTO.class); }
@Test public void getAllNonDeletedDtoShouldReturnThreeElementListWhenThereAreThreeChannels() { // Given given(channelRepository.findAllByDeletedFalse()).willReturn(expectedChannelEntityList); given(converterService.convert(expectedChannelEntityList, ChannelDTO.class)) .willReturn(expectedChannelDTOList); // When Collection<ChannelDTO> result = channelService.getAllNonDeletedDto(); // Then assertEquals(result, expectedChannelDTOList); then(channelRepository).should().findAllByDeletedFalse(); then(converterService).should().convert(expectedChannelEntityList, ChannelDTO.class); }
@Test public void getAllNonDeletedDtoShouldReturnEmptyListWhenThereAreNoChannels() { // Given given(channelRepository.findAllByDeletedFalse()).willReturn(EMPTY_CHANNEL_ENTITY_LIST); given(converterService.convert(EMPTY_CHANNEL_ENTITY_LIST, ChannelDTO.class)) .willReturn(EMPTY_CHANNEL_DTO_LIST); // When Collection<ChannelDTO> channels = channelService.getAllNonDeletedDto(); // Then assertThat(channels, notNullValue()); assertTrue(channels.isEmpty()); then(channelRepository).should().findAllByDeletedFalse(); then(converterService).should().convert(EMPTY_CHANNEL_ENTITY_LIST, ChannelDTO.class); }
@Test public void getAllNonDeletedDtoShouldReturnSingleElementListWhenThereIsOneChannel() { // Given List<ChannelEntity> channels = Arrays.asList(facebookEntity); List<ChannelDTO> expected = Arrays.asList(facebookDto); given(channelRepository.findAllByDeletedFalse()).willReturn(channels); given(converterService.convert(channels, ChannelDTO.class)).willReturn(expected); // When Collection<ChannelDTO> result = channelService.getAllNonDeletedDto(); // Then assertEquals(result, expected); then(channelRepository).should().findAllByDeletedFalse(); then(converterService).should().convert(channels, ChannelDTO.class); }