RecipientServiceImpl implements RecipientService { @Override public Recipient save(String accountName, Recipient recipient) { recipient.setAccountName(accountName); recipient.getScheduledNotifications().values() .forEach(settings -> { if (settings.getLastNotified() == null) { settings.setLastNotified(new Date()); } }); repository.save(recipient); log.info("recipient {} settings has been updated", recipient); return recipient; }  @Override Recipient findByAccountName(String accountName); @Override Recipient save(String accountName, Recipient recipient); @Override List<Recipient> findReadyToNotify(NotificationType type); @Override void markNotified(NotificationType type, Recipient recipient);  }
@Test public void shouldSaveRecipient() { NotificationSettings remind = new NotificationSettings(); remind.setActive(true); remind.setFrequency(Frequency.WEEKLY); remind.setLastNotified(null); NotificationSettings backup = new NotificationSettings(); backup.setActive(false); backup.setFrequency(Frequency.MONTHLY); backup.setLastNotified(new Date()); Recipient recipient = new Recipient(); recipient.setEmail("test@test.com"); recipient.setScheduledNotifications(ImmutableMap.of( NotificationType.BACKUP, backup, NotificationType.REMIND, remind )); Recipient saved = recipientService.save("test", recipient); verify(repository).save(recipient); assertNotNull(saved.getScheduledNotifications().get(NotificationType.REMIND).getLastNotified()); assertEquals("test", saved.getAccountName()); }