From ff74fb60ab87ff0b983bcab69a388ebf153f6aae Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 4 Jun 2013 10:16:25 +0200 Subject: [PATCH] Display prefixes "Rule" and "Message" in issue change emails --- .../IssueChangesEmailTemplate.java | 9 ++------- .../IssueChangesEmailTemplateTest.java | 20 ------------------- .../email_with_changes.txt | 4 ++-- ...with_issue_message_same_than_rule_name.txt | 6 ------ 4 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_issue_message_same_than_rule_name.txt diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java index 43dff3e911f..31408445e4c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java @@ -85,14 +85,9 @@ public class IssueChangesEmailTemplate extends EmailTemplate { } private void appendHeader(Notification notif, StringBuilder sb) { - String ruleName = notif.getFieldValue("ruleName"); - String issueMessage = notif.getFieldValue("message"); - appendLine(sb, StringUtils.defaultString(notif.getFieldValue("componentName"), notif.getFieldValue("componentKey"))); - appendLine(sb, ruleName); - if (!Objects.equal(ruleName, issueMessage)) { - appendLine(sb, issueMessage); - } + appendField(sb, "Rule", null, notif.getFieldValue("ruleName")); + appendField(sb, "Message", null, notif.getFieldValue("message")); } private void appendFooter(StringBuilder sb, Notification notification) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java index 7814c072c73..64384c40f39 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java @@ -84,26 +84,6 @@ public class IssueChangesEmailTemplateTest { assertThat(email.getFrom()).isNull(); } - @Test - public void test_email_with_issue_message_same_than_rule_name() { - Notification notification = new Notification("issue-changes") - .setFieldValue("projectName", "Struts") - .setFieldValue("projectKey", "org.apache:struts") - .setFieldValue("componentName", "org.apache.struts.Action") - .setFieldValue("key", "ABCDE") - .setFieldValue("new.assignee", "louis") - - // same rule name and issue msg -> display once - .setFieldValue("ruleName", "Avoid Cycles") - .setFieldValue("message", "Avoid Cycles"); - - EmailMessage email = template.format(notification); - String message = email.getMessage(); - String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_issue_message_same_than_rule_name.txt"); - expectedMessage = StringUtils.remove(expectedMessage, '\r'); - assertThat(message).isEqualTo(expectedMessage); - } - @Test public void notification_sender_should_be_the_author_of_change() { User user = mock(User.class); diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_changes.txt b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_changes.txt index 113d0ba6abb..d6f50cce261 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_changes.txt +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_changes.txt @@ -1,6 +1,6 @@ org.apache.struts.Action -Avoid Cycles -Has 3 cycles +Rule: Avoid Cycles +Message: Has 3 cycles Comment: How to fix it? Assignee: louis (was simon) diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_issue_message_same_than_rule_name.txt b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_issue_message_same_than_rule_name.txt deleted file mode 100644 index f97b5d17be4..00000000000 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_issue_message_same_than_rule_name.txt +++ /dev/null @@ -1,6 +0,0 @@ -org.apache.struts.Action -Avoid Cycles - -Assignee: louis - -See it in SonarQube: http://nemo.sonarsource.org/issue/show/ABCDE -- 2.39.5