From bd5ee214d49c00a887a560f27ede91078ffbbce6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 28 Sep 2017 10:45:19 +0200 Subject: [PATCH] SONAR-8730 use existing L18n for types in new issue notifications --- .../AbstractNewIssuesEmailTemplate.java | 2 +- .../MyNewIssuesEmailTemplateTest.java | 6 +++--- .../NewIssuesEmailTemplateTest.java | 6 +++--- .../tests/issue/IssueNotificationsTest.java | 21 ++++++++----------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java index 8f6626c70a1..7a5eb221ac5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java @@ -179,7 +179,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { for (Iterator 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()); + String ruleTypeLabel = i18n.message(getLocale(), "issue.type." + ruleType, ruleType.name()); message.append(ruleTypeLabel).append(": ").append(notification.getFieldValue(Metric.RULE_TYPE + DOT + ruleType + COUNT)); if (ruleTypeIterator.hasNext()) { message.append(TAB); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index 1c88818d3c3..13092a3ba2f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -63,9 +63,9 @@ public class MyNewIssuesEmailTemplateTest { // returns the login passed in parameter when(userIndex.getNullableByLogin(anyString())) .thenAnswer((Answer) invocationOnMock -> new UserDoc().setName((String) invocationOnMock.getArguments()[0])); - when(i18n.message(any(Locale.class), eq("rule_type.BUG"), anyString())).thenReturn("Bug"); - when(i18n.message(any(Locale.class), eq("rule_type.CODE_SMELL"), anyString())).thenReturn("Code Smell"); - when(i18n.message(any(Locale.class), eq("rule_type.VULNERABILITY"), anyString())).thenReturn("Vulnerability"); + when(i18n.message(any(Locale.class), eq("issue.type.BUG"), anyString())).thenReturn("Bug"); + when(i18n.message(any(Locale.class), eq("issue.type.CODE_SMELL"), anyString())).thenReturn("Code Smell"); + when(i18n.message(any(Locale.class), eq("issue.type.VULNERABILITY"), anyString())).thenReturn("Vulnerability"); underTest = new MyNewIssuesEmailTemplate(settings, i18n); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index d674904afe2..02872c4f408 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -61,9 +61,9 @@ public class NewIssuesEmailTemplateTest { // returns the login passed in parameter when(userIndex.getNullableByLogin(anyString())) .thenAnswer((Answer) invocationOnMock -> new UserDoc().setName((String) invocationOnMock.getArguments()[0])); - when(i18n.message(any(Locale.class), eq("rule_type.CODE_SMELL"), anyString())).thenReturn("Code Smell"); - when(i18n.message(any(Locale.class), eq("rule_type.VULNERABILITY"), anyString())).thenReturn("Vulnerability"); - when(i18n.message(any(Locale.class), eq("rule_type.BUG"), anyString())).thenReturn("Bug"); + when(i18n.message(any(Locale.class), eq("issue.type.CODE_SMELL"), anyString())).thenReturn("Code Smell"); + when(i18n.message(any(Locale.class), eq("issue.type.VULNERABILITY"), anyString())).thenReturn("Vulnerability"); + when(i18n.message(any(Locale.class), eq("issue.type.BUG"), anyString())).thenReturn("Bug"); template = new NewIssuesEmailTemplate(settings, i18n); } diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java index 477f3ab48d3..62b6117fdaf 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java @@ -90,7 +90,6 @@ public class IssueNotificationsTest { @Parameter public boolean privateProject; - @BeforeClass public static void setUp() { smtpServer = new Wiser(0); @@ -151,13 +150,13 @@ public class IssueNotificationsTest { extractBodies(smtpServer.getMessages()).forEach( message -> assertThat(message) - .contains("Project: Sample") - .contains("Version: " + version) - .contains("17 new issues (new debt: 17min)") - .contains("Type") - .contains("One Issue Per Line (xoo): 17") - .contains("More details at: http://localhost:9000/project/issues?id=sample&createdAt=2015-12-15T00%3A00%3A00%2B") - ); + .contains("Project: Sample") + .contains("Version: " + version) + .contains("17 new issues (new debt: 17min)") + .contains("Type") + .contains("Bug: ").contains("Code Smell: ").contains("Vulnerability: ") + .contains("One Issue Per Line (xoo): 17") + .contains("More details at: http://localhost:9000/project/issues?id=sample&createdAt=2015-12-15T00%3A00%3A00%2B")); clearSmtpMessages(); } @@ -202,8 +201,7 @@ public class IssueNotificationsTest { "sonar.projectVersion", version, "sonar.scm.provider", "xoo", "sonar.scm.disabled", "false", - "sonar.exclusions", "**/*" - ); + "sonar.exclusions", "**/*"); // No email since all code is ignored waitUntilAllNotificationsAreDelivered(1); @@ -213,8 +211,7 @@ public class IssueNotificationsTest { runAnalysis("issue/xoo-with-scm", "sonar.projectVersion", version, "sonar.scm.provider", "xoo", - "sonar.scm.disabled", "false" - ); + "sonar.scm.disabled", "false"); // We expect to receive a notification for each subscriber with UserRole.user // And a personalized email for the assignee userWithUserRole -- 2.39.5