From 99a0fa8de0b365f67c3c6b05656b4767530a5b01 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 8 Mar 2016 20:00:51 +0100 Subject: [PATCH] SONAR-7345 Remove no more used IssueChangelogFormatter --- .../issue/InternalRubyIssueService.java | 7 +- .../server/issue/IssueChangelogFormatter.java | 88 --------- .../server/issue/IssueChangelogService.java | 15 +- .../platformlevel/PlatformLevel4.java | 10 +- .../issue/InternalRubyIssueServiceTest.java | 7 - .../issue/IssueChangelogFormatterTest.java | 183 ------------------ .../issue/IssueChangelogServiceTest.java | 21 +- 7 files changed, 9 insertions(+), 322 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java index 1689511d525..2d9cf99c9f0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java @@ -40,8 +40,6 @@ import org.sonar.api.web.UserRole; import org.sonar.core.issue.ActionPlanStats; import org.sonar.core.issue.DefaultActionPlan; import org.sonar.core.issue.DefaultIssueComment; -import org.sonar.core.issue.FieldDiffs; -import org.sonar.server.issue.workflow.Transition; import org.sonar.db.component.ResourceDao; import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ResourceQuery; @@ -50,6 +48,7 @@ import org.sonar.server.es.SearchOptions; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.issue.actionplan.ActionPlanService; import org.sonar.server.issue.filter.IssueFilterService; +import org.sonar.server.issue.workflow.Transition; import org.sonar.server.search.QueryContext; import org.sonar.server.user.UserSession; import org.sonar.server.util.RubyUtils; @@ -129,10 +128,6 @@ public class InternalRubyIssueService { return changelogService.changelog(issue); } - public List formatChangelog(FieldDiffs diffs) { - return changelogService.formatDiffs(diffs); - } - public List findComments(String issueKey) { return commentService.findComments(issueKey); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java deleted file mode 100644 index e9e7e55faae..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.issue; - -import java.io.Serializable; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.sonar.api.server.ServerSide; -import org.sonar.api.i18n.I18n; -import org.sonar.core.issue.FieldDiffs; -import org.sonar.api.utils.Duration; -import org.sonar.api.utils.Durations; -import org.sonar.server.user.UserSession; - -import static com.google.common.collect.Lists.newArrayList; - -@ServerSide -public class IssueChangelogFormatter { - - private static final String ISSUE_CHANGELOG_FIELD = "issue.changelog.field."; - - private final I18n i18n; - private final Durations durations; - private final UserSession userSession; - - public IssueChangelogFormatter(I18n i18n, Durations durations, UserSession userSession) { - this.i18n = i18n; - this.durations = durations; - this.userSession = userSession; - } - - public List format(Locale locale, FieldDiffs diffs) { - List result = newArrayList(); - for (Map.Entry entry : diffs.diffs().entrySet()) { - StringBuilder message = new StringBuilder(); - String key = entry.getKey(); - IssueChangelogDiffFormat diffFormat = format(key, entry.getValue()); - if (diffFormat.newValue() != null) { - message.append(i18n.message(locale, "issue.changelog.changed_to", null, i18n.message(locale, ISSUE_CHANGELOG_FIELD + key, null), diffFormat.newValue())); - } else { - message.append(i18n.message(locale, "issue.changelog.removed", null, i18n.message(locale, ISSUE_CHANGELOG_FIELD + key, null))); - } - if (diffFormat.oldValue() != null) { - message.append(" ("); - message.append(i18n.message(locale, "issue.changelog.was", null, diffFormat.oldValue())); - message.append(")"); - } - result.add(message.toString()); - } - return result; - } - - private IssueChangelogDiffFormat format(String key, FieldDiffs.Diff diff) { - Serializable newValue = diff.newValue(); - Serializable oldValue = diff.oldValue(); - - String newValueString = newValue != null && !"".equals(newValue) ? newValue.toString() : null; - String oldValueString = oldValue != null && !"".equals(oldValue) ? oldValue.toString() : null; - if (IssueUpdater.TECHNICAL_DEBT.equals(key)) { - if (newValueString != null) { - newValueString = durations.format(userSession.locale(), Duration.create(Long.parseLong(newValueString)), Durations.DurationFormat.SHORT); - } - if (oldValueString != null) { - oldValueString = durations.format(userSession.locale(), Duration.create(Long.parseLong(oldValueString)), Durations.DurationFormat.SHORT); - } - } - return new IssueChangelogDiffFormat(oldValueString, newValueString); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogService.java index 7c8c5b46cb0..b8af151cba4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogService.java @@ -21,13 +21,12 @@ package org.sonar.server.issue; import java.util.Collection; import java.util.List; -import org.sonar.api.server.ServerSide; import org.sonar.api.issue.Issue; -import org.sonar.core.issue.FieldDiffs; +import org.sonar.api.server.ServerSide; import org.sonar.api.user.User; import org.sonar.api.user.UserFinder; +import org.sonar.core.issue.FieldDiffs; import org.sonar.db.issue.IssueChangeDao; -import org.sonar.server.user.UserSession; import static com.google.common.collect.Lists.newArrayList; @@ -40,15 +39,11 @@ public class IssueChangelogService { private final IssueChangeDao changeDao; private final UserFinder userFinder; private final IssueService issueService; - private final IssueChangelogFormatter formatter; - private final UserSession userSession; - public IssueChangelogService(IssueChangeDao changeDao, UserFinder userFinder, IssueService issueService, IssueChangelogFormatter formatter, UserSession userSession) { + public IssueChangelogService(IssueChangeDao changeDao, UserFinder userFinder, IssueService issueService) { this.changeDao = changeDao; this.userFinder = userFinder; this.issueService = issueService; - this.formatter = formatter; - this.userSession = userSession; } public IssueChangelog changelog(String issueKey) { @@ -69,8 +64,4 @@ public class IssueChangelogService { Collection users = userFinder.findByLogins(logins); return new IssueChangelog(changes, users); } - - public List formatDiffs(FieldDiffs diffs) { - return formatter.format(userSession.locale(), diffs); - } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 11bc5632d64..a1a7fab232a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -31,10 +31,6 @@ import org.sonar.api.rules.AnnotationRuleParser; import org.sonar.api.rules.XMLRuleParser; import org.sonar.api.server.rule.RulesDefinitionXmlLoader; import org.sonar.core.component.DefaultResourceTypes; -import org.sonar.server.issue.SetTypeAction; -import org.sonar.server.issue.IssueUpdater; -import org.sonar.server.issue.workflow.FunctionExecutor; -import org.sonar.server.issue.workflow.IssueWorkflow; import org.sonar.core.timemachine.Periods; import org.sonar.core.user.DefaultUserFinder; import org.sonar.core.user.DeprecatedUserFinder; @@ -116,15 +112,16 @@ import org.sonar.server.issue.AssignAction; import org.sonar.server.issue.CommentAction; import org.sonar.server.issue.InternalRubyIssueService; import org.sonar.server.issue.IssueBulkChangeService; -import org.sonar.server.issue.IssueChangelogFormatter; import org.sonar.server.issue.IssueChangelogService; import org.sonar.server.issue.IssueCommentService; import org.sonar.server.issue.IssueQueryService; import org.sonar.server.issue.IssueService; +import org.sonar.server.issue.IssueUpdater; import org.sonar.server.issue.PlanAction; import org.sonar.server.issue.RemoveTagsAction; import org.sonar.server.issue.ServerIssueStorage; import org.sonar.server.issue.SetSeverityAction; +import org.sonar.server.issue.SetTypeAction; import org.sonar.server.issue.TransitionAction; import org.sonar.server.issue.actionplan.ActionPlanService; import org.sonar.server.issue.actionplan.ActionPlanWs; @@ -140,6 +137,8 @@ import org.sonar.server.issue.notification.MyNewIssuesNotificationDispatcher; import org.sonar.server.issue.notification.NewIssuesEmailTemplate; import org.sonar.server.issue.notification.NewIssuesNotificationDispatcher; import org.sonar.server.issue.notification.NewIssuesNotificationFactory; +import org.sonar.server.issue.workflow.FunctionExecutor; +import org.sonar.server.issue.workflow.IssueWorkflow; import org.sonar.server.issue.ws.IssueWsModule; import org.sonar.server.language.ws.LanguageWs; import org.sonar.server.measure.MeasureFilterEngine; @@ -586,7 +585,6 @@ public class PlatformLevel4 extends PlatformLevel { ActionService.class, Actions.class, IssueBulkChangeService.class, - IssueChangelogFormatter.class, WsResponseCommonFormat.class, IssueWsModule.class, IssueService.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java index 7a331cf1e54..03fa3fddcfc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java @@ -645,13 +645,6 @@ public class InternalRubyIssueServiceTest { verify(issueBulkChangeService).execute(any(IssueBulkChangeQuery.class), any(ThreadLocalUserSession.class)); } - @Test - public void format_changelog() { - FieldDiffs fieldDiffs = new FieldDiffs(); - service.formatChangelog(fieldDiffs); - verify(changelogService).formatDiffs(eq(fieldDiffs)); - } - @Test public void max_query_size() { assertThat(service.maxPageSize()).isEqualTo(500); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java deleted file mode 100644 index bcf5faec749..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.issue; - -import java.util.List; -import java.util.Locale; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.i18n.I18n; -import org.sonar.core.issue.FieldDiffs; -import org.sonar.api.utils.Duration; -import org.sonar.api.utils.Durations; -import org.sonar.server.tester.UserSessionRule; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class IssueChangelogFormatterTest { - - private static final Locale DEFAULT_LOCALE = Locale.getDefault(); - - @Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - - @Mock - private I18n i18n; - - @Mock - private Durations durations; - - - private IssueChangelogFormatter formatter; - - @Before - public void before() { - formatter = new IssueChangelogFormatter(i18n, durations, userSessionRule); - } - - @Test - public void format_field_diffs_with_new_and_old_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("severity", "BLOCKER", "INFO"); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Severity changed to INFO (was BLOCKER)"); - } - - @Test - public void format_field_diffs_with_only_new_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("severity", null, "INFO"); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Severity changed to INFO"); - } - - @Test - public void format_field_diffs_with_only_old_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("severity", "BLOCKER", null); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Severity removed (was BLOCKER)"); - } - - @Test - public void format_field_diffs_without_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("severity", null, null); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Severity removed"); - } - - @Test - public void format_field_diffs_with_empty_old_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("severity", "", null); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Severity removed"); - } - - @Test - public void format_technical_debt_with_old_and_new_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("technicalDebt", "18000", "28800"); - - when(durations.format(any(Locale.class), eq(Duration.create(18000L)), eq(Durations.DurationFormat.SHORT))).thenReturn("5 hours"); - when(durations.format(any(Locale.class), eq(Duration.create(28800L)), eq(Durations.DurationFormat.SHORT))).thenReturn("1 days"); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "5 hours")).thenReturn("was 5 hours"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Technical Debt changed to 1 days (was 5 hours)"); - } - - @Test - public void format_technical_debt_with_new_value_only() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("technicalDebt", null, "28800"); - - when(durations.format(any(Locale.class), eq(Duration.create(28800L)), eq(Durations.DurationFormat.SHORT))).thenReturn("1 days"); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Technical Debt changed to 1 days"); - } - - @Test - public void format_technical_debt_without_value() { - FieldDiffs diffs = new FieldDiffs(); - diffs.setDiff("technicalDebt", null, null); - - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); - when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Technical Debt")).thenReturn("Technical Debt removed"); - - List result = formatter.format(DEFAULT_LOCALE, diffs); - assertThat(result).hasSize(1); - String message = result.get(0); - assertThat(message).isEqualTo("Technical Debt removed"); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogServiceTest.java index d42f0d7c62b..6fd219c8281 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogServiceTest.java @@ -20,9 +20,7 @@ package org.sonar.server.issue; import java.util.Arrays; -import java.util.Locale; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -33,20 +31,13 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.FieldDiffs; import org.sonar.core.user.DefaultUser; import org.sonar.db.issue.IssueChangeDao; -import org.sonar.server.tester.UserSessionRule; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class IssueChangelogServiceTest { - @Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - @Mock IssueChangeDao changeDao; @@ -56,14 +47,11 @@ public class IssueChangelogServiceTest { @Mock IssueService issueService; - @Mock - IssueChangelogFormatter formatter; - IssueChangelogService service; @Before public void setUp() { - service = new IssueChangelogService(changeDao, userFinder, issueService, formatter, userSessionRule); + service = new IssueChangelogService(changeDao, userFinder, issueService); } @Test @@ -99,11 +87,4 @@ public class IssueChangelogServiceTest { assertThat(changelog.changes().get(0).diffs()).containsKeys("effort"); } - @Test - public void format_diffs() { - FieldDiffs diffs = new FieldDiffs().setUserLogin("arthur").setDiff("severity", "MAJOR", "BLOCKER"); - userSessionRule.login(); - service.formatDiffs(diffs); - verify(formatter).format(any(Locale.class), eq(diffs)); - } } -- 2.39.5