@Test void update() { when(objectMapper.convertValue(messageDto1, Message.class)).thenReturn(message1); when(messageRepository.save(message1)).thenReturn(message1); assertThat(messageService.update(messageDto1)).isEqualTo(message1); }
@Transactional @Override public Message update(MessageDto messageDto) { Message m = repository.findByTypeAndName(messageDto.getType(), messageDto.getName()).orElseThrow(() -> new RuntimeException("Message not found")); messageDto.setId(m.getId()); Message newM = objectMapper.convertValue(messageDto, Message.class); return repository.save(newM); }
MessageServiceImpl implements MessageService { @Transactional @Override public Message update(MessageDto messageDto) { Message m = repository.findByTypeAndName(messageDto.getType(), messageDto.getName()).orElseThrow(() -> new RuntimeException("Message not found")); messageDto.setId(m.getId()); Message newM = objectMapper.convertValue(messageDto, Message.class); return repository.save(newM); } }
MessageServiceImpl implements MessageService { @Transactional @Override public Message update(MessageDto messageDto) { Message m = repository.findByTypeAndName(messageDto.getType(), messageDto.getName()).orElseThrow(() -> new RuntimeException("Message not found")); messageDto.setId(m.getId()); Message newM = objectMapper.convertValue(messageDto, Message.class); return repository.save(newM); } MessageServiceImpl(MessageRepository repository, ObjectMapper objectMapper); }
MessageServiceImpl implements MessageService { @Transactional @Override public Message update(MessageDto messageDto) { Message m = repository.findByTypeAndName(messageDto.getType(), messageDto.getName()).orElseThrow(() -> new RuntimeException("Message not found")); messageDto.setId(m.getId()); Message newM = objectMapper.convertValue(messageDto, Message.class); return repository.save(newM); } 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 { @Transactional @Override public Message update(MessageDto messageDto) { Message m = repository.findByTypeAndName(messageDto.getType(), messageDto.getName()).orElseThrow(() -> new RuntimeException("Message not found")); messageDto.setId(m.getId()); Message newM = objectMapper.convertValue(messageDto, Message.class); return repository.save(newM); } 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);  }