]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8610 Remove setting sonar.technicalDebt.hoursInDay
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 31 Jan 2017 16:39:29 +0000 (17:39 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 2 Feb 2017 16:05:25 +0000 (17:05 +0100)
20 files changed:
it/it-tests/src/test/java/it/qualityModel/DebtConfigurationRule.java
it/it-tests/src/test/java/it/qualityModel/TechnicalDebtInIssueChangelogTest.java
it/it-tests/src/test/java/it/qualityModel/TechnicalDebtTest.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitygate/EvaluationResultTextConverterImpl.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java
server/sonar-server/src/main/java/org/sonar/server/property/ws/IndexAction.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DebtCalculatorTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalActionTest/settings.json
server/sonar-web/src/main/js/helpers/measures.js
sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java
sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/Durations.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationsTest.java

index 57c6e844ac623052b82c1c057f2534ad4a043b44..11ca09aa744316ca350b934173b6568f549da184 100644 (file)
@@ -33,7 +33,6 @@ import static util.ItUtils.setServerProperty;
  */
 public class DebtConfigurationRule extends ExternalResource {
 
-  private static final String HOURS_IN_DAY_PROPERTY = "sonar.technicalDebt.hoursInDay";
   private static final String DEV_COST_PROPERTY = "sonar.technicalDebt.developmentCost";
   private static final String RATING_GRID_PROPERTY = "sonar.technicalDebt.ratingGrid";
 
@@ -71,21 +70,10 @@ public class DebtConfigurationRule extends ExternalResource {
   }
 
   public void reset() {
-    resetHoursInDay();
     resetDevelopmentCost();
     resetRatingGrid();
   }
 
-  public DebtConfigurationRule updateHoursInDay(int hoursInDay) {
-    setProperty(HOURS_IN_DAY_PROPERTY, Integer.toString(hoursInDay));
-    return this;
-  }
-
-  public DebtConfigurationRule resetHoursInDay() {
-    resetProperty(HOURS_IN_DAY_PROPERTY);
-    return this;
-  }
-
   public DebtConfigurationRule updateDevelopmentCost(int developmentCost) {
     setProperty(DEV_COST_PROPERTY, Integer.toString(developmentCost));
     return this;
index ab44372993fa5ada353525c4b295dc50302df7a7..89bc42c742b1fb640c634c2c81a9e0c094fbf513 100644 (file)
@@ -52,9 +52,6 @@ public class TechnicalDebtInIssueChangelogTest {
   @Before
   public void deleteAnalysisData() {
     orchestrator.resetData();
-
-    // Set hours in day property to 8
-    debtConfiguration.updateHoursInDay(8);
   }
 
   @Test
index f4ba792a436b3cd88aac6353663d2cdfe1e40fe6..32d4b4c6bfdc4e1957621352a156849db499a868 100644 (file)
@@ -29,7 +29,6 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.wsclient.issue.Issue;
-import org.sonar.wsclient.issue.IssueClient;
 import org.sonar.wsclient.issue.IssueQuery;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -46,9 +45,6 @@ public class TechnicalDebtTest {
   @Before
   public void deleteAnalysisData() {
     orchestrator.resetData();
-
-    // Set hours in day property to 8
-    debtConfiguration.updateHoursInDay(8);
   }
 
   /**
@@ -71,44 +67,4 @@ public class TechnicalDebtTest {
     }
   }
 
-  @Test
-  public void use_hours_in_day_property_to_display_debt() throws Exception {
-    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/qualityModel/one-issue-per-file.xml"));
-    orchestrator.getServer().provisionProject("sample", "sample");
-    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-file");
-
-    // One day -> 10 hours
-    debtConfiguration.updateHoursInDay(10);
-
-    orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))
-      // As OneIssuePerFile has a debt of 10 minutes, we multiply it by 72 to have 1 day and 2 hours of technical debt
-      .setProperties("sonar.oneIssuePerFile.effortToFix", "72")
-      );
-
-    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
-    Issue issue = issueClient.find(IssueQuery.create()).list().get(0);
-
-    assertThat(issue.debt()).isEqualTo("1d2h");
-  }
-
-  @Test
-  public void use_hours_in_day_property_during_analysis_to_convert_debt() throws Exception {
-    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/qualityModel/one-day-debt-per-file.xml"));
-    orchestrator.getServer().provisionProject("sample", "sample");
-    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-day-debt-per-file");
-
-    // One day -> 10 hours : debt will be stored as 360.000 seconds (1 day * 10 hours per day * 60 * 60)
-    debtConfiguration.updateHoursInDay(10);
-
-    orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
-
-    // Issue debt was 1 day during analysis but will be displayed as 1 day and 2 hours (hours in day property was set
-    // to 10 during analysis but is now 8)
-    debtConfiguration.updateHoursInDay(8);
-
-    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
-    Issue issue = issueClient.find(IssueQuery.create()).list().get(0);
-    assertThat(issue.debt()).isEqualTo("1d2h");
-  }
-
 }
index 8b7449846e3197b984e0895db6608bacfce57833..5a09fc50825b36601789e28620cbbe0570d1432f 100644 (file)
@@ -109,7 +109,7 @@ public class ComputeEngineContainerImplTest {
         + 25 // level 1
         + 47 // content of DaoModule
         + 3 // content of EsSearchModule
-        + 63 // content of CorePropertyDefinitions
+        + 62 // content of CorePropertyDefinitions
         + 1 // content of CePropertyDefinitions
     );
     assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
index c330349ac82f99745ccf0aa37518d0c107e8928d..9b91fac65c0643cf070d80b1e131a00f0d12aadb 100644 (file)
@@ -100,6 +100,6 @@ public final class EvaluationResultTextConverterImpl implements EvaluationResult
   }
 
   private String formatDuration(String value) {
-    return durations.format(Locale.ENGLISH, Duration.create(Long.parseLong(value)), Durations.DurationFormat.SHORT);
+    return durations.format(Duration.create(Long.parseLong(value)));
   }
 }
index afd0f5f593bf6eb2ea70a0878044f900c5e082d7..6cf98fd7afe4a6779b0f3ea2c9ec471e166dd857 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.issue.notification;
 import com.google.common.collect.Multiset;
 import java.util.Date;
 import java.util.List;
-import java.util.Locale;
 import org.sonar.api.notifications.Notification;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.Severity;
@@ -140,7 +139,7 @@ public class NewIssuesNotification extends Notification {
   }
 
   public NewIssuesNotification setDebt(Duration debt) {
-    setFieldValue(Metric.DEBT + COUNT, durations.format(Locale.ENGLISH, debt));
+    setFieldValue(Metric.DEBT + COUNT, durations.format(debt));
     return this;
   }
 
index 743d9d1c5a16686fd3e57c98a47e3cd68b50394c..5bfe298d9514ed93277e28fb1fc0457ac100d824 100644 (file)
@@ -84,7 +84,7 @@ public class IndexAction implements WsAction {
       .setHandler(this);
     action.createParam(PARAM_ID)
       .setDescription("Setting key")
-      .setExampleValue("sonar.technicalDebt.hoursInDay");
+      .setExampleValue("sonar.test.inclusions");
     action.createParam(PARAM_COMPONENT)
       .setDescription("Component key or database id")
       .setExampleValue(KEY_PROJECT_EXAMPLE_001);
index 175d494989d6f1b106febfc02bf6ab08c4b1184a..9e6e6ef96eabfc4e5e61b1e363a76c6f336a3f92 100644 (file)
@@ -100,7 +100,7 @@ public class ValuesAction implements SettingsWsAction {
       .setExampleValue(KEY_PROJECT_EXAMPLE_001);
     action.createParam(PARAM_KEYS)
       .setDescription("List of setting keys")
-      .setExampleValue("sonar.technicalDebt.hoursInDay,sonar.dbcleaner.cleanDirectory");
+      .setExampleValue("sonar.test.inclusions,sonar.dbcleaner.cleanDirectory");
   }
 
   @Override
index 1304be1966099b8d4aea630f6e4d56f88c0e0f01..1f931512ae0cf42c2ea29a15c80b89b735b94731 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.db.Database;
 import org.sonar.db.dialect.H2;
 import org.sonar.server.ui.PageRepository;
 
-import static org.sonar.api.CoreProperties.HOURS_IN_DAY;
 import static org.sonar.api.CoreProperties.RATING_GRID;
 import static org.sonar.core.config.WebConstants.SONAR_LF_ENABLE_GRAVATAR;
 import static org.sonar.core.config.WebConstants.SONAR_LF_GRAVATAR_SERVER_URL;
@@ -50,7 +49,6 @@ public class GlobalAction implements NavigationWsAction {
     SONAR_LF_ENABLE_GRAVATAR,
     SONAR_LF_GRAVATAR_SERVER_URL,
     SONAR_UPDATECENTER_ACTIVATE,
-    HOURS_IN_DAY,
     RATING_GRID);
 
   private final PageRepository pageRepository;
index 47f03a90c5956de08bc5d0b1c7e35e470cd1abc9..bef24054066ca437a83af6ef6d92aed2db2489d9 100644 (file)
@@ -15,7 +15,6 @@
     "sonar.lf.enableGravatar": "true",
     "sonar.lf.gravatarServerUrl": "http://some-server.tld/logo.png",
     "sonar.updatecenter.activate": "false",
-    "sonar.technicalDebt.hoursInDay": "10",
     "sonar.technicalDebt.ratingGrid": "0.05,0.1,0.2,0.5"
   },
   "logoUrl": "http://example.com/my-custom-logo.png",
index a47e6356333ce14a2ddc28b5638ab66cff5c4ba2..2fe25ad0e283d38e4620a59cb609edcf9fcfaa97 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.computation.task.projectanalysis.issue;
 
 import org.junit.Test;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.i18n.I18n;
 import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction;
 import org.sonar.api.utils.Durations;
@@ -29,7 +27,6 @@ import org.sonar.core.issue.DefaultIssue;
 import org.sonar.db.rule.RuleTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
 
 public class DebtCalculatorTest {
 
@@ -39,7 +36,7 @@ public class DebtCalculatorTest {
   @org.junit.Rule
   public RuleRepositoryRule ruleRepository = new RuleRepositoryRule().add(rule);
 
-  DebtCalculator underTest = new DebtCalculator(ruleRepository, new Durations(new MapSettings(), mock(I18n.class)));
+  DebtCalculator underTest = new DebtCalculator(ruleRepository, new Durations());
 
   @Test
   public void no_debt_if_function_is_not_defined() {
index 23353762b2ecee47f090c6fe7f909f1a29008f21..4dcc7542776d20ab864f082703875ac820a3c791 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.issue.notification;
 
 import com.google.common.collect.Lists;
 import java.util.Date;
-import java.util.Locale;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.sonar.api.rule.RuleKey;
@@ -107,7 +106,7 @@ public class NewIssuesNotificationTest {
 
   @Test
   public void set_debt() {
-    when(durations.format(any(Locale.class), any(Duration.class))).thenReturn("55 min");
+    when(durations.format(any(Duration.class))).thenReturn("55 min");
 
     underTest.setDebt(Duration.create(55));
 
index ce5fec92fc3c44e1368ba8615639d23ce4e52afc..1bcd3f4f3fcc042746dd2ff47d05ff167e661fb3 100644 (file)
@@ -89,7 +89,6 @@ public class GlobalActionTest {
     settings.setProperty("sonar.lf.gravatarServerUrl", "https://secure.gravatar.com/avatar/{EMAIL_MD5}.jpg?s={SIZE}&d=identicon");
     settings.setProperty("sonar.lf.enableGravatar", true);
     settings.setProperty("sonar.updatecenter.activate", false);
-    settings.setProperty("sonar.technicalDebt.hoursInDay", "10");
     settings.setProperty("sonar.technicalDebt.ratingGrid", "0.05,0.1,0.2,0.5");
     // This setting should be ignored as it's not needed
     settings.setProperty("sonar.defaultGroup", "sonar-users");
@@ -164,7 +163,6 @@ public class GlobalActionTest {
     settings.setProperty("sonar.lf.gravatarServerUrl", "http://some-server.tld/logo.png");
     settings.setProperty("sonar.lf.enableGravatar", true);
     settings.setProperty("sonar.updatecenter.activate", false);
-    settings.setProperty("sonar.technicalDebt.hoursInDay", "10");
     settings.setProperty("sonar.technicalDebt.ratingGrid", "0.05,0.1,0.2,0.5");
     settings.setProperty("sonar.allowUsersToSignUp", true);
     when(server.getVersion()).thenReturn("6.2");
index dfd79237733341c949f1758ac67bdc5f2677714b..3fc38cdd2a0265c37acc2c7d853ed0c2c4635939 100644 (file)
@@ -5,7 +5,6 @@
     "sonar.lf.gravatarServerUrl": "https://secure.gravatar.com/avatar/{EMAIL_MD5}.jpg?s={SIZE}&d=identicon",
     "sonar.lf.enableGravatar": "true",
     "sonar.updatecenter.activate": "false",
-    "sonar.technicalDebt.hoursInDay": "10",
     "sonar.technicalDebt.ratingGrid": "0.05,0.1,0.2,0.5"
   }
 }
index cf3188c45bb0d7545c597430995fe5f2b4316b61..afd6afb23d83c98bcb004166c8545a643c62bcdd 100644 (file)
@@ -286,13 +286,7 @@ function formatDurationShort (isNegative, days, hours, minutes) {
 }
 
 function getHoursInDay () {
-  // workaround cyclic dependencies
-  const getStore = require('../app/utils/getStore').default;
-  const { getSettingValue } = require('../store/rootReducer');
-
-  const store = getStore();
-  const settingValue = getSettingValue(store.getState(), 'sonar.technicalDebt.hoursInDay');
-  return settingValue ? settingValue.value : 8;
+  return 8;
 }
 
 function durationFormatter (value) {
index 230e6c0a279fa51980754743bdb6a9a68cd471cb..ee07fa924ef2437cfa1865fa8a4528db77790368 100644 (file)
@@ -34,14 +34,6 @@ class DebtProperties {
 
   static List<PropertyDefinition> all() {
     return ImmutableList.of(
-      PropertyDefinition.builder(CoreProperties.HOURS_IN_DAY)
-        .name("Number of working hours in a day")
-        .type(PropertyType.INTEGER)
-        .defaultValue("8")
-        .category(CoreProperties.CATEGORY_TECHNICAL_DEBT)
-        .deprecatedKey("sqale.hoursInDay")
-        .build(),
-
       PropertyDefinition.builder(CoreProperties.DEVELOPMENT_COST)
         .defaultValue("" + CoreProperties.DEVELOPMENT_COST_DEF_VALUE)
         .name("Development cost")
@@ -78,9 +70,7 @@ class DebtProperties {
             .name("Development cost")
             .description("If left blank, the generic value defined in this section will be used.")
             .type(PropertyType.FLOAT)
-            .build()
-        )
-        .build()
-      );
+            .build())
+        .build());
   }
 }
index 470cc2f2ed81179e26db2635bf9554924432a791..bf9d2501497eb5f27d889b81f3d83b9904fd6a41 100644 (file)
@@ -35,7 +35,7 @@ public class CorePropertyDefinitionsTest {
   @Test
   public void all() {
     List<PropertyDefinition> defs = CorePropertyDefinitions.all();
-    assertThat(defs).hasSize(65);
+    assertThat(defs).hasSize(64);
   }
 
   @Test
index 273224793d98a7b2ca9d0ba99d62226116d67094..f5e43721afd5dba85a463318de3e64392656ccf0 100644 (file)
@@ -428,7 +428,9 @@ public interface CoreProperties {
 
   /**
    * @since 4.0
+   * @deprecated no more used since 6.3. See https://jira.sonarsource.com/browse/SONAR-8610
    */
+  @Deprecated
   String HOURS_IN_DAY = "sonar.technicalDebt.hoursInDay";
 
   /**
index 4e682c64a35ffb0adab58c66b53349132fee9935..0053e66501341b8d8a33478ffab73fd7473254bc 100644 (file)
 package org.sonar.api.utils;
 
 import java.util.Locale;
-import javax.annotation.CheckForNull;
-import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
-import org.sonar.api.i18n.I18n;
 import org.sonar.api.server.ServerSide;
 
 /**
@@ -36,6 +32,16 @@ import org.sonar.api.server.ServerSide;
 @ComputeEngineSide
 public class Durations {
 
+  private static final String MINUTES_FORMAT = "%smin";
+  private static final String HOURS_FORMAT = "%sh";
+  private static final String DAYS_FORMAT = "%sd";
+
+  private static final int HOURS_IN_DAY = 8;
+
+  /**
+   * @deprecated since 6.3, only one format is available
+   */
+  @Deprecated
   public enum DurationFormat {
     /**
      * Display duration with only one or two members.
@@ -44,14 +50,6 @@ public class Durations {
     SHORT
   }
 
-  private final Settings settings;
-  private final I18n i18n;
-
-  public Durations(Settings settings, I18n i18n) {
-    this.settings = settings;
-    this.i18n = i18n;
-  }
-
   /**
    * Create a Duration object from a number of minutes
    */
@@ -62,40 +60,52 @@ public class Durations {
   /**
    * Convert the text to a Duration
    * <br>
-   * Example : decode("9d 10 h") -&gt; Duration.encode("10d2h") (if sonar.technicalDebt.hoursInDay property is set to 8)
+   * Example : decode("9d 10 h") -&gt; Duration.encode("10d2h")
    * <br>
    * @throws IllegalArgumentException
    */
   public Duration decode(String duration) {
-    return Duration.decode(duration, hoursInDay());
+    return Duration.decode(duration, HOURS_IN_DAY);
   }
 
   /**
    * Return the string value of the Duration.
    * <br>
-   * Example : encode(Duration.encode("9d 10h")) -&gt; "10d2h" (if sonar.technicalDebt.hoursInDay property is set to 8)
+   * Example : encode(Duration.encode("9d 10h")) -&gt; "10d2h"
    */
   public String encode(Duration duration) {
-    return duration.encode(hoursInDay());
+    return duration.encode(HOURS_IN_DAY);
   }
 
   /**
    * Return the formatted work duration.
-   * <br>
-   * Example : format(Locale.FRENCH, Duration.encode("9d 10h"), DurationFormat.SHORT) -&gt; 10j 2h (if sonar.technicalDebt.hoursInDay property is set to 8)
    *
+   * @deprecated since 6.3 as the {@link Locale#ENGLISH} is always used. Use {@link #format(Duration)} instead
    */
+  @Deprecated
   public String format(Locale locale, Duration duration, DurationFormat format) {
-    return format(locale, duration);
+    return format(duration);
   }
 
   /**
    * Return the formatted work duration.
    * <br>
-   * Example : format(Locale.FRENCH, Duration.encode("9d 10h"), DurationFormat.SHORT) -&gt; 10j 2h (if sonar.technicalDebt.hoursInDay property is set to 8)
+   * Example : format(Locale.FRENCH, Duration.encode("9d 10h"), DurationFormat.SHORT) -&gt; 10d 2d
    *
+   * @deprecated since 6.3 as the {@link Locale#ENGLISH} is always used. Use {@link #format(Duration)} instead
    */
+  @Deprecated
   public String format(Locale locale, Duration duration) {
+    return format(duration);
+  }
+
+  /**
+   * Return the formatted work duration using the english bundles.
+   * <br>
+   * Example : format(Duration.encode("9d 10h")) -&gt; 10d 2h
+   *
+   */
+  public String format(Duration duration) {
     Long durationInMinutes = duration.toMinutes();
     if (durationInMinutes == 0) {
       return "0";
@@ -103,35 +113,31 @@ public class Durations {
     boolean isNegative = durationInMinutes < 0;
     Long absDuration = Math.abs(durationInMinutes);
 
-    int days = ((Double) ((double) absDuration / hoursInDay() / 60)).intValue();
-    Long remainingDuration = absDuration - (days * hoursInDay() * 60);
+    int days = ((Double) ((double) absDuration / HOURS_IN_DAY / 60)).intValue();
+    Long remainingDuration = absDuration - (days * HOURS_IN_DAY * 60);
     int hours = ((Double) (remainingDuration.doubleValue() / 60)).intValue();
     remainingDuration = remainingDuration - (hours * 60);
     int minutes = remainingDuration.intValue();
 
-    return format(locale, days, hours, minutes, isNegative);
+    return format(days, hours, minutes, isNegative);
   }
 
-  private String format(Locale locale, int days, int hours, int minutes, boolean isNegative) {
+  private static String format(int days, int hours, int minutes, boolean isNegative) {
     StringBuilder message = new StringBuilder();
     if (days > 0) {
-      message.append(message(locale, "work_duration.x_days", isNegative ? (-1 * days) : days));
+      message.append(String.format(DAYS_FORMAT, isNegative ? (-1 * days) : days));
     }
     if (displayHours(days, hours)) {
       addSpaceIfNeeded(message);
-      message.append(message(locale, "work_duration.x_hours", isNegative && message.length() == 0 ? (-1 * hours) : hours));
+      message.append(String.format(HOURS_FORMAT, isNegative && message.length() == 0 ? (-1 * hours) : hours));
     }
     if (displayMinutes(days, hours, minutes)) {
       addSpaceIfNeeded(message);
-      message.append(message(locale, "work_duration.x_minutes", isNegative && message.length() == 0 ? (-1 * minutes) : minutes));
+      message.append(String.format(MINUTES_FORMAT, isNegative && message.length() == 0 ? (-1 * minutes) : minutes));
     }
     return message.toString();
   }
 
-  private String message(Locale locale, String key, @CheckForNull Object parameter) {
-    return i18n.message(locale, key, null, parameter);
-  }
-
   private static boolean displayHours(int days, int hours) {
     return hours > 0 && days < 10;
   }
@@ -146,8 +152,4 @@ public class Durations {
     }
   }
 
-  private int hoursInDay() {
-    return settings.getInt(CoreProperties.HOURS_IN_DAY);
-  }
-
 }
index 409da22f7519e63127e9f9c7caf9b91cdad78602..301bc0af9e9de70feaf1759bc0702f7601417f49 100644 (file)
  */
 package org.sonar.api.utils;
 
-import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.i18n.I18n;
-
-import java.util.Locale;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
 public class DurationsTest {
 
-  static final int HOURS_IN_DAY = 8;
-
-  static final long ONE_MINUTE = 1L;
-  static final long ONE_HOUR = ONE_MINUTE * 60;
-  static final long ONE_DAY = HOURS_IN_DAY * ONE_HOUR;
-
-  @Mock
-  I18n i18n;
-
-  Locale locale = Locale.ENGLISH;
-
-  Settings settings;
+  private static final int HOURS_IN_DAY = 8;
 
-  Durations durations;
+  private static final long ONE_MINUTE = 1L;
+  private static final long ONE_HOUR = ONE_MINUTE * 60;
+  private static final long ONE_DAY = HOURS_IN_DAY * ONE_HOUR;
 
-  @Before
-  public void setUp() {
-    settings = new MapSettings();
-    settings.setProperty(CoreProperties.HOURS_IN_DAY, HOURS_IN_DAY);
-    durations = new Durations(settings, i18n);
-  }
+  private Durations underTest = new Durations();
 
   @Test
   public void create_from_minutes() {
-    assertThat(durations.create(10L).toMinutes()).isEqualTo(10L);
+    assertThat(underTest.create(10L).toMinutes()).isEqualTo(10L);
   }
 
   @Test
   public void decode() {
     // 1 working day -> 8 hours
-    assertThat(durations.decode("1d").toMinutes()).isEqualTo(8L * ONE_HOUR);
+    assertThat(underTest.decode("1d").toMinutes()).isEqualTo(8L * ONE_HOUR);
     // 8 hours
-    assertThat(durations.decode("8h").toMinutes()).isEqualTo(8L * ONE_HOUR);
+    assertThat(underTest.decode("8h").toMinutes()).isEqualTo(8L * ONE_HOUR);
   }
 
   @Test
   public void format() {
-    when(i18n.message(eq(locale), eq("work_duration.x_days"), eq((String) null), eq(5))).thenReturn("5d");
-    when(i18n.message(eq(locale), eq("work_duration.x_hours"), eq((String) null), eq(2))).thenReturn("2h");
-    when(i18n.message(eq(locale), eq("work_duration.x_minutes"), eq((String) null), eq(1))).thenReturn("1min");
-
-    assertThat(durations.format(locale, Duration.create(5 * ONE_DAY), Durations.DurationFormat.SHORT)).isEqualTo("5d");
-    assertThat(durations.format(locale, Duration.create(2 * ONE_HOUR), Durations.DurationFormat.SHORT)).isEqualTo("2h");
-    assertThat(durations.format(locale, Duration.create(ONE_MINUTE), Durations.DurationFormat.SHORT)).isEqualTo("1min");
+    assertThat(underTest.format(Duration.create(5 * ONE_DAY))).isEqualTo("5d");
+    assertThat(underTest.format(Duration.create(2 * ONE_HOUR))).isEqualTo("2h");
+    assertThat(underTest.format(Duration.create(ONE_MINUTE))).isEqualTo("1min");
 
-    assertThat(durations.format(locale, Duration.create(5 * ONE_DAY + 2 * ONE_HOUR), Durations.DurationFormat.SHORT)).isEqualTo("5d 2h");
-    assertThat(durations.format(locale, Duration.create(2 * ONE_HOUR + ONE_MINUTE), Durations.DurationFormat.SHORT)).isEqualTo("2h 1min");
-    assertThat(durations.format(locale, Duration.create(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE), Durations.DurationFormat.SHORT)).isEqualTo("5d 2h");
+    assertThat(underTest.format(Duration.create(5 * ONE_DAY + 2 * ONE_HOUR))).isEqualTo("5d 2h");
+    assertThat(underTest.format(Duration.create(2 * ONE_HOUR + ONE_MINUTE))).isEqualTo("2h 1min");
+    assertThat(underTest.format(Duration.create(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE))).isEqualTo("5d 2h");
   }
 
   @Test
   public void not_display_following_element_when_bigger_than_ten() {
-    int hoursInDay = 15;
-    settings.setProperty(CoreProperties.HOURS_IN_DAY, Integer.toString(hoursInDay));
-
-    when(i18n.message(eq(locale), eq("work_duration.x_days"), eq((String) null), eq(15))).thenReturn("15d");
-    when(i18n.message(eq(locale), eq("work_duration.x_hours"), eq((String) null), eq(12))).thenReturn("12h");
-
-    assertThat(durations.format(locale, Duration.create(15 * hoursInDay * ONE_HOUR + 2 * ONE_HOUR + ONE_MINUTE), Durations.DurationFormat.SHORT)).isEqualTo("15d");
-    assertThat(durations.format(locale, Duration.create(12 * ONE_HOUR + ONE_MINUTE), Durations.DurationFormat.SHORT)).isEqualTo("12h");
+    assertThat(underTest.format(Duration.create(15 * ONE_DAY + 7 * ONE_HOUR + ONE_MINUTE))).isEqualTo("15d");
   }
 
   @Test
   public void display_zero_without_unit() {
-    assertThat(durations.format(locale, Duration.create(0), Durations.DurationFormat.SHORT)).isEqualTo("0");
+    assertThat(underTest.format(Duration.create(0))).isEqualTo("0");
   }
 
   @Test
   public void display_negative_duration() {
-    when(i18n.message(eq(locale), eq("work_duration.x_days"), eq((String) null), eq(-5))).thenReturn("-5d");
-    when(i18n.message(eq(locale), eq("work_duration.x_hours"), eq((String) null), eq(-2))).thenReturn("-2h");
-    when(i18n.message(eq(locale), eq("work_duration.x_minutes"), eq((String) null), eq(-1))).thenReturn("-1min");
-
-    assertThat(durations.format(locale, Duration.create(-5 * ONE_DAY), Durations.DurationFormat.SHORT)).isEqualTo("-5d");
-    assertThat(durations.format(locale, Duration.create(-2 * ONE_HOUR), Durations.DurationFormat.SHORT)).isEqualTo("-2h");
-    assertThat(durations.format(locale, Duration.create(-1 * ONE_MINUTE), Durations.DurationFormat.SHORT)).isEqualTo("-1min");
+    assertThat(underTest.format(Duration.create(-5 * ONE_DAY))).isEqualTo("-5d");
+    assertThat(underTest.format(Duration.create(-2 * ONE_HOUR))).isEqualTo("-2h");
+    assertThat(underTest.format(Duration.create(-1 * ONE_MINUTE))).isEqualTo("-1min");
   }
 
 }