@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_issues_grouped_by_status_closed_or_any_other_when_change_from_analysis() {
    Project project = newProject("foo");
    Rule rule = newRandomNotAHotspotRule("bar");
    Set<ChangedIssue> changedIssues = Arrays.stream(ISSUE_STATUSES)
      .map(status -> newChangedIssue(status + "", status, project, rule))
      .collect(toSet());
    AnalysisChange analysisChange = newAnalysisChange();

    EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues));

    HtmlListAssert htmlListAssert = HtmlFragmentAssert.assertThat(emailMessage.getMessage())
      .hasParagraph().hasParagraph() // skip header
      .hasParagraph("Closed issue:")
      .withoutLink()
      .hasList("Rule " + rule.getName() + " - See the single issue")
      .withLinkOn("See the single issue")
      .hasParagraph("Open issues:")
      .withoutLink()
      .hasList("Rule " + rule.getName() + " - See all " + (ISSUE_STATUSES.length - 1) + " issues")
      .withLinkOn("See all " + (ISSUE_STATUSES.length - 1) + " issues");
    verifyEnd(htmlListAssert);
  }