@Test public void format_email_with_all_fields_filled() { Notification notification = newNotification(32); addTags(notification); addRules(notification); addComponents(notification); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()).startsWith( "Project: Struts\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + " Rules\n" + " Rule the Universe (Clojure): 42\n" + " Rule the World (Java): 5\n" + "\n" + " Tags\n" + " oscar: 3\n" + " cesar: 10\n" + "\n" + " Most impacted files\n" + " /path/to/file: 3\n" + " /path/to/directory: 7\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); }
private void assertStartsWithFile(String message, String resourcePath) throws IOException { String fileContent = IOUtils.toString(getClass().getResource(resourcePath), StandardCharsets.UTF_8); assertThat(sanitizeString(message)).startsWith(sanitizeString(fileContent)); }
@Test public void message_id() { Notification notification = newNotification(32); EmailMessage message = underTest.format(notification); assertThat(message.getMessageId()).isEqualTo("my-new-issues/org.apache:struts"); }
@Test public void subject() { Notification notification = newNotification(32); EmailMessage message = underTest.format(notification); assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts"); }
@Test public void format_email_supports_single_issue() { Notification notification = newNotification(1); EmailMessage message = underTest.format(notification); assertThat(message.getSubject()) .isEqualTo("You have 1 new issue on project Struts"); assertThat(message.getMessage()) .contains("1 new issue (new debt: 1d3h)\n"); }
@Test public void subject_on_branch() { Notification notification = newNotification(32) .setFieldValue("branch", "feature1"); EmailMessage message = underTest.format(notification); assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts (feature1)"); }
@Test public void format_supports_null_version() { Notification notification = newNotification(32) .setFieldValue("branch", "feature1"); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()) .startsWith("Project: Struts\n" + "Branch: feature1\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); }
@Test public void format_email_with_no_assignees_tags_nor_components() { Notification notification = newNotification(32) .setFieldValue("projectVersion", "52.0"); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()) .startsWith("Project: Struts\n" + "Version: 52.0\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); }
@Test public void format_email_with_issue_on_branch() { Notification notification = newNotification(32) .setFieldValue("projectVersion", "52.0") .setFieldValue("branch", "feature1"); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()) .startsWith("Project: Struts\n" + "Branch: feature1\n" + "Version: 52.0\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); }