@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"); } }
@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 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 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); }
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); }
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);  }