}
protected void appendRuleType(StringBuilder message, Notification notification) {
+ String count = notification.getFieldValue(Metric.RULE_TYPE + COUNT);
message
- .append(String.format("%s new issues (new debt: %s)",
- notification.getFieldValue(Metric.RULE_TYPE + COUNT),
+ .append(String.format("%s new issue%s (new debt: %s)",
+ count,
+ Integer.valueOf(count) > 1 ? "s" : "",
notification.getFieldValue(Metric.EFFORT + COUNT)))
.append(NEW_LINE).append(NEW_LINE)
.append(TAB)
.append(TAB)
.append(TAB);
-
for (Iterator<RuleType> ruleTypeIterator = Arrays.asList(RuleType.BUG, RuleType.VULNERABILITY, RuleType.CODE_SMELL).iterator(); ruleTypeIterator.hasNext();) {
RuleType ruleType = ruleTypeIterator.next();
String ruleTypeLabel = i18n.message(getLocale(), "rule_type." + ruleType, ruleType.name());
@Test
public void format_email_with_all_fields_filled() throws Exception {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
addTags(notification);
addRules(notification);
addComponents(notification);
@Test
public void message_id() {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
EmailMessage message = underTest.format(notification);
@Test
public void subject() {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
EmailMessage message = underTest.format(notification);
@Test
public void format_email_with_no_assignees_tags_nor_components() throws Exception {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
EmailMessage message = underTest.format(notification);
"32 new issues (new debt: 1d3h)\n" +
"\n" +
" Type\n" +
- " Bug: 1 Vulnerability: 3 Code Smell: 0\n" +
+ " Bug: 1 Vulnerability: 3 Code Smell: 0\n" +
"\n" +
"See it in SonarQube: 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() throws Exception {
- Notification notification = newNotification()
+ Notification notification = newNotification(32)
.setFieldValue("branch", "feature1");
EmailMessage message = underTest.format(notification);
"See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18");
}
+ @Test
+ public void format_email_supports_single_issue() {
+ Notification notification = newNotification(1);
+
+ EmailMessage message = underTest.format(notification);
+
+ assertThat(message.getMessage())
+ .contains("1 new issue (new debt: 1d3h)\n");
+ }
+
@Test
public void do_not_add_footer_when_properties_missing() {
Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE)
assertThat(message.getMessage()).doesNotContain("See it");
}
- private Notification newNotification() {
+ private Notification newNotification(int count) {
return new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE)
.setFieldValue("projectName", "Struts")
.setFieldValue("projectKey", "org.apache:struts")
.setFieldValue("projectDate", "2010-05-18T14:50:45+0000")
.setFieldValue("assignee", "lo.gin")
.setFieldValue(EFFORT + ".count", "1d3h")
- .setFieldValue(RULE_TYPE + ".count", "32")
+ .setFieldValue(RULE_TYPE + ".count", String.valueOf(count))
.setFieldValue(RULE_TYPE + ".BUG.count", "1")
.setFieldValue(RULE_TYPE + ".VULNERABILITY.count", "3")
.setFieldValue(RULE_TYPE + ".CODE_SMELL.count", "0");
@Test
public void message_id() {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
EmailMessage message = template.format(notification);
@Test
public void subject() {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
EmailMessage message = template.format(notification);
@Test
public void format_email_with_all_fields_filled() throws Exception {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
addAssignees(notification);
addRules(notification);
addTags(notification);
@Test
public void format_email_with_no_assignees_tags_nor_components() throws Exception {
- Notification notification = newNotification();
+ Notification notification = newNotification(32);
EmailMessage message = template.format(notification);
"See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1");
}
+ @Test
+ public void format_email_supports_single_issue() {
+ Notification notification = newNotification(1);
+
+ EmailMessage message = template.format(notification);
+
+ assertThat(message.getMessage())
+ .contains("1 new issue (new debt: 1d3h)\n");
+ }
+
@Test
public void format_email_with_issue_on_branch() throws Exception {
- Notification notification = newNotification()
+ Notification notification = newNotification(32)
.setFieldValue("branch", "feature1");
EmailMessage message = template.format(notification);
assertThat(message.getMessage()).doesNotContain("See it");
}
- private Notification newNotification() {
+ private Notification newNotification(int count) {
return new Notification(NewIssuesNotification.TYPE)
.setFieldValue("projectName", "Struts")
.setFieldValue("projectKey", "org.apache:struts")
.setFieldValue("projectUuid", "ABCDE")
.setFieldValue("projectDate", "2010-05-18T14:50:45+0000")
.setFieldValue(EFFORT + ".count", "1d3h")
- .setFieldValue(RULE_TYPE + ".count", "32")
+ .setFieldValue(RULE_TYPE + ".count", String.valueOf(count))
.setFieldValue(RULE_TYPE + ".BUG.count", "1")
.setFieldValue(RULE_TYPE + ".CODE_SMELL.count", "3")
.setFieldValue(RULE_TYPE + ".VULNERABILITY.count", "10");