@Override
  @CheckForNull
  public EmailMessage format(Notification notif) {
    if (!(notif instanceof ChangesOnMyIssuesNotification)) {
      return null;
    }

    ChangesOnMyIssuesNotification notification = (ChangesOnMyIssuesNotification) notif;

    if (notification.getChange() instanceof AnalysisChange) {
      checkState(!notification.getChangedIssues().isEmpty(), "changedIssues can't be empty");
      return formatAnalysisNotification(notification.getChangedIssues().keySet().iterator().next(), notification);
    }
    return formatMultiProject(notification);
  }
@Test
  public void format_set_html_message_with_issue_status_title_handles_plural_when_change_from_analysis() {
    Project project = newProject("foo");
    Rule rule = newRandomNotAHotspotRule("bar");
    Set<ChangedIssue> closedIssues = IntStream.range(0, 2 + new Random().nextInt(5))
      .mapToObj(status -> newChangedIssue(status + "", STATUS_CLOSED, project, rule))
      .collect(toSet());
    Set<ChangedIssue> openIssues = IntStream.range(0, 2 + new Random().nextInt(5))
      .mapToObj(status -> newChangedIssue(status + "", STATUS_OPEN, project, rule))
      .collect(toSet());
    AnalysisChange analysisChange = newAnalysisChange();

    EmailMessage closedIssuesMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, closedIssues));
    EmailMessage openIssuesMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, openIssues));

    HtmlListAssert htmlListAssert = HtmlFragmentAssert.assertThat(closedIssuesMessage.getMessage())
      .hasParagraph().hasParagraph() // skip header
      .hasParagraph("Closed issues:")
      .hasList();
    verifyEnd(htmlListAssert);
    htmlListAssert = HtmlFragmentAssert.assertThat(openIssuesMessage.getMessage())
      .hasParagraph().hasParagraph() // skip header
      .hasParagraph("Open issues:")
      .hasList();
    verifyEnd(htmlListAssert);
  }