From e31f0cb9ba5a1901a0c7987ab9dac415d1744c30 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Tue, 6 Apr 2021 18:17:57 -0400 Subject: [PATCH] Don't send email notification when 0 uploads were attempted (#1058) * Don't send email notification when 0 uploads were attempted --- .../reporting/icann/IcannReportingUploadAction.java | 12 +++++++++--- .../icann/IcannReportingUploadActionTest.java | 8 +------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java index 8c67c24f4..b32f7710a 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java @@ -278,9 +278,15 @@ public final class IcannReportingUploadAction implements Runnable { } private void emailUploadResults(ImmutableMap reportSummary) { - String subject = String.format( - "ICANN Monthly report upload summary: %d/%d succeeded", - reportSummary.values().stream().filter((b) -> b).count(), reportSummary.size()); + if (reportSummary.size() == 0) { + logger.atInfo().log("No uploads were attempted today; skipping notification email."); + return; + } + String subject = + String.format( + "ICANN Monthly report upload summary: %d/%d succeeded", + // This filter() does in fact do something: It counts only the trues. + reportSummary.values().stream().filter((b) -> b).count(), reportSummary.size()); String body = String.format( "Report Filename - Upload status:\n%s", diff --git a/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java b/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java index f292a1fe7..3c4203975 100644 --- a/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java +++ b/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java @@ -210,13 +210,7 @@ class IcannReportingUploadActionTest { action.run(); tm().clearSessionCache(); verifyNoMoreInteractions(mockReporter); - verify(emailService) - .sendEmail( - EmailMessage.create( - "ICANN Monthly report upload summary: 0/0 succeeded", - "Report Filename - Upload status:\n", - new InternetAddress("recipient@example.com"), - new InternetAddress("sender@example.com"))); + verifyNoMoreInteractions(emailService); } @TestOfyAndSql