### Question:
MessageServiceImpl implements MessageService { @Override public MessageDto getMessageByTypeAndName(MessageType type, String name) { Message m = repository.findByTypeAndName(type, name).orElseThrow(() -> new RuntimeException("Message not found")); return objectMapper.convertValue(m, MessageDto.class); } 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 getMessageByTypeAndName() { MessageDto result = messageService.getMessageByTypeAndName(MessageType.REFERRAL_SHARE, "message1"); assertThat(result).isEqualTo(messageDto1); }
@Test void getMessageByTypeAndName_throwsExceptionWhenNotFound() { when(messageRepository.findByTypeAndName(MessageType.REFERRAL_SHARE, "doesnotexist")) .thenReturn(Optional.empty()); try { messageService.getMessageByTypeAndName(MessageType.REFERRAL_SHARE, "doesnotexist"); failBecauseExceptionWasNotThrown(RuntimeException.class); } catch (RuntimeException e) { assertThat(e.getMessage()).isEqualTo("Message not found"); } }