### Question:
MessageServiceImpl implements MessageService { @Override public MessageDto getMessageByKey(String key) { int indexSeperator = key.indexOf('.'); if (indexSeperator > 0) { String type = key.substring(0, indexSeperator); String name = key.substring(indexSeperator + 1); return getMessageByTypeAndName(MessageType.valueOf(type.toUpperCase()), name); } else { return null; } } 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 getMessageByKey() { MessageDto result = messageService.getMessageByKey("REFERRAL_SHARE.message1"); assertThat(result).isEqualTo(messageDto1); }
@Test void getMessageByKey_invalidKey() { MessageDto result = messageService.getMessageByKey("INVALIDKEY"); assertThat(result).isNull(); }