]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9725 support singular in subject of new issue notifications
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 28 Sep 2017 08:31:28 +0000 (10:31 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 2 Oct 2017 11:03:35 +0000 (13:03 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java

index ec3ccd8a80333bc5c6bb117f02481eb74b0f8b86..8f6626c70a1262e6b12735201a9d7c6a84fa13bc 100644 (file)
@@ -111,9 +111,11 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate {
   protected abstract boolean shouldNotFormat(Notification notification);
 
   protected String subject(Notification notification, String fullProjectName) {
-    return String.format("%s: %s new issues (new debt: %s)",
+    int issueCount = Integer.parseInt(notification.getFieldValue(Metric.RULE_TYPE + COUNT));
+    return String.format("%s: %s new issue%s (new debt: %s)",
       fullProjectName,
-      notification.getFieldValue(Metric.RULE_TYPE + COUNT),
+      issueCount,
+      issueCount > 1 ? "s" : "",
       notification.getFieldValue(Metric.EFFORT + COUNT));
   }
 
index fcf02e34b469f626a12db0b8499f89d7e449da85..dd75a4cf95c00aea1630c45ce00438211af54f80 100644 (file)
@@ -47,8 +47,10 @@ public class MyNewIssuesEmailTemplate extends AbstractNewIssuesEmailTemplate {
 
   @Override
   protected String subject(Notification notification, String fullProjectName) {
-    return String.format("You have %s new issues on project %s",
-      notification.getFieldValue(Metric.RULE_TYPE + COUNT),
+    int issueCount = Integer.parseInt(notification.getFieldValue(Metric.RULE_TYPE + COUNT));
+    return String.format("You have %s new issue%s on project %s",
+      issueCount,
+      issueCount > 1 ? "s" : "",
       fullProjectName);
   }
 
index 98741da80e77bff8fb6b04cc194eed7c0168fbd3..1c88818d3c35dd8d63012525bc771b8f59809eb9 100644 (file)
@@ -185,6 +185,8 @@ public class MyNewIssuesEmailTemplateTest {
 
     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");
   }
index 36d78f01ae0c179f85348d0a7f46aba4bbb04614..d674904afe249f8828c4a72d5602b659702456fc 100644 (file)
@@ -167,6 +167,8 @@ public class NewIssuesEmailTemplateTest {
 
     EmailMessage message = template.format(notification);
 
+    assertThat(message.getSubject())
+      .isEqualTo("Struts: 1 new issue (new debt: 1d3h)");
     assertThat(message.getMessage())
       .contains("1 new issue (new debt: 1d3h)\n");
   }