### Question:
Recipient { public void markNotified(@NonNull NotificationType type) { Validate.notNull(type); Optional.ofNullable(getNotifications().get(type)) .ifPresent(settings -> { Validate.isTrue(settings.isActive()); settings.markNotified(); }); } @Builder @SuppressWarnings("unused") private  Recipient(@NonNull String username, @NonNull String email,
                      @NonNull @Singular Map<NotificationType, NotificationSettings> notifications); void markNotified(@NonNull NotificationType type); @Override String toString();  }### Answer:
@Test void shouldMarkRecipientNotified() { NotificationSettings backup = NotificationSettings.builder() .active(false) .frequency(Frequency.MONTHLY) .build(); NotificationSettings remind = NotificationSettings.builder() .active(true) .frequency(Frequency.WEEKLY) .build(); Recipient recipient = Recipient.builder() .username(USERNAME) .email(EMAIL) .notification(NotificationType.BACKUP, backup) .notification(NotificationType.REMIND, remind) .build(); recipient.markNotified(NotificationType.REMIND); assertThat(recipient.getNotifications().get(NotificationType.BACKUP).isNotified()).isFalse(); assertThat(recipient.getNotifications().get(NotificationType.REMIND).isNotified()).isTrue(); }
@Test void shouldFailToMarkRecipientNotifiedIfNotificationInactive() { NotificationSettings backup = NotificationSettings.builder() .active(false) .frequency(Frequency.MONTHLY) .build(); Recipient recipient = Recipient.builder() .username(USERNAME) .email(EMAIL) .notification(NotificationType.BACKUP, backup) .build(); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> recipient.markNotified(NotificationType.BACKUP)); }
@Test void shouldNotMarkRecipientNotifiedIfBackupNotificationIsNotSet() { NotificationSettings remind = NotificationSettings.builder() .active(true) .frequency(Frequency.WEEKLY) .build(); Recipient recipient = Recipient.builder() .username(USERNAME) .email(EMAIL) .notification(NotificationType.REMIND, remind) .build(); recipient.markNotified(NotificationType.BACKUP); assertThat(recipient.getNotifications()).containsOnlyKeys(NotificationType.REMIND); }