DownloadBatchStatusNotificationDispatcher { void updateNotification(InternalDownloadBatchStatus downloadBatchStatus) { if (downloadBatchStatus.notificationSeen()) { Logger.v("DownloadBatchStatus:", downloadBatchStatus.getDownloadBatchId(), "notification has already been seen."); return; } String rawDownloadBatchId = downloadBatchStatus.getDownloadBatchId().rawId(); if (downloadBatchStatus.status() == DELETED) { downloadBatchIdNotificationSeen.remove(rawDownloadBatchId); } if (notificationIsNotMarkedAsSeenYet(downloadBatchStatus, rawDownloadBatchId)) { downloadBatchIdNotificationSeen.add(rawDownloadBatchId); Logger.v("start updateNotificationSeenAsync " + rawDownloadBatchId + ", seen: " + NOTIFICATION_SEEN + ", status: " + downloadBatchStatus.status()); downloadBatchStatus.markAsNotificationSeen(notificationSeenPersistence); } notificationDispatcher.updateNotification(downloadBatchStatus); } DownloadBatchStatusNotificationDispatcher(DownloadsNotificationSeenPersistence notificationSeenPersistence,
                                              ServiceNotificationDispatcher<DownloadBatchStatus> notificationDispatcher,
                                              Set<String> downloadBatchIdNotificationSeen);   }
@Test public void updatesNotificationSeen_whenStatusIsDownloaded() { InternalDownloadBatchStatus downloadedBatchStatus = anInternalDownloadsBatchStatus().withStatus(DownloadBatchStatus.Status.DOWNLOADED).build(); downloadBatchStatusNotificationDispatcher.updateNotification(downloadedBatchStatus); verify(persistence).updateNotificationSeenAsync(downloadedBatchStatus, true); }
@Test public void doesNothing_whenNotificationHasBeenSeen() { InternalDownloadBatchStatus notificationSeenStatus = anInternalDownloadsBatchStatus().withNotificationSeen(true).build(); downloadBatchStatusNotificationDispatcher.updateNotification(notificationSeenStatus); verifyZeroInteractions(notificationDispatcher, persistence); }
@Test public void updatesNotification_whenNotificationHasNotBeenSeen() { InternalDownloadBatchStatus notificationNotSeenStatus = anInternalDownloadsBatchStatus().withNotificationSeen(false).build(); downloadBatchStatusNotificationDispatcher.updateNotification(notificationNotSeenStatus); verify(notificationDispatcher).updateNotification(notificationNotSeenStatus); }