]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7345 Remove no more used IssueChangelogFormatter 824/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 8 Mar 2016 19:00:51 +0000 (20:00 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Mar 2016 09:44:17 +0000 (10:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogService.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogServiceTest.java

index 1689511d5252f31be4298ccc26104c893d16896a..2d9cf99c9f049236d5eac858ac3017ed284f1692 100644 (file)
@@ -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<String> formatChangelog(FieldDiffs diffs) {
-    return changelogService.formatDiffs(diffs);
-  }
-
   public List<DefaultIssueComment> 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 (file)
index e9e7e55..0000000
+++ /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<String> format(Locale locale, FieldDiffs diffs) {
-    List<String> result = newArrayList();
-    for (Map.Entry<String, FieldDiffs.Diff> 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);
-  }
-
-}
index 7c8c5b46cb07f94d7f37480ad7940f6a48f4da6c..b8af151cba4e426e77fdb0cce42ce629adcbe68e 100644 (file)
@@ -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<User> users = userFinder.findByLogins(logins);
     return new IssueChangelog(changes, users);
   }
-
-  public List<String> formatDiffs(FieldDiffs diffs) {
-    return formatter.format(userSession.locale(), diffs);
-  }
 }
index 11bc5632d64dc7b5d3ed1bd11478c3fc2c0440c8..a1a7fab232a635ba86badb5a51d98d30de56404a 100644 (file)
@@ -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,
index 7a331cf1e54b1599f496bf345b8c3fe6020bd810..03fa3fddcfc50e889e8ec693577efbaee45e8f19 100644 (file)
@@ -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 (file)
index bcf5fae..0000000
+++ /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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> result = formatter.format(DEFAULT_LOCALE, diffs);
-    assertThat(result).hasSize(1);
-    String message = result.get(0);
-    assertThat(message).isEqualTo("Technical Debt removed");
-  }
-
-}
index d42f0d7c62b6c15b99f6b4b39978e272b10d1f5f..6fd219c8281adbc51404843e4c44daeaffb7aa50 100644 (file)
@@ -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));
-  }
 }