### Question:
MessageServiceImpl implements MessageService { @Transactional(readOnly = true) @Override public List<MessageDto> getMessagesByType(MessageType type) { return repository.findByType(type, new Sort(Sort.Direction.DESC, "name")) .stream() .parallel() .map(m -> objectMapper.convertValue(m, MessageDto.class)) .collect(Collectors.toList()); } MessageServiceImpl(MessageRepository repository, ObjectMapper objectMapper); @Transactional(readOnly = true) @Override List<MessageDto> getMessagesByType(MessageType type); @Override MessageDto getMessageByKey(String key); @Override MessageDto getMessageByTypeAndName(MessageType type, String name); @Transactional @Override Message update(MessageDto messageDto); @Transactional @Override Message add(MessageDto messageDto); @Transactional @Override void delete(MessageType type, String name);  }### Answer:
@Test void getMessagesByType() { Message message2 = mock(Message.class); Message message3 = mock(Message.class); MessageDto messageDto2 = mock(MessageDto.class); MessageDto messageDto3 = mock(MessageDto.class); when(objectMapper.convertValue(same(message2), eq(MessageDto.class))).thenReturn(messageDto2); when(objectMapper.convertValue(same(message3), eq(MessageDto.class))).thenReturn(messageDto3); when(messageRepository.findByType(MessageType.REFERRAL_SHARE, new Sort(Sort.Direction.DESC, "name"))) .thenReturn(Arrays.asList(message1, message2, message3)); List<MessageDto> result = messageService.getMessagesByType(MessageType.REFERRAL_SHARE); assertThat(result).containsExactly(messageDto1, messageDto2, messageDto3); }