]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7570 A duration of 0 minute should be converted to "0min" instead of empty 914/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 28 Apr 2016 08:16:36 +0000 (10:16 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 28 Apr 2016 11:36:33 +0000 (13:36 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java

index 4eab07e4b8f165b0332a51afcb1e2917b8f6eb0c..7020978e305ac7359fbac74a2bb68b4e71ff3f6e 100644 (file)
@@ -121,7 +121,7 @@ public class Duration implements Serializable {
       stringBuilder.append(minutes);
       stringBuilder.append(MINUTE);
     }
-    return stringBuilder.toString();
+    return stringBuilder.length() == 0 ? ("0" + MINUTE) : stringBuilder.toString();
   }
 
   /**
index ba427bd3197cfe0d317191c330940932b0549879..b3c03a5edd2d405556a0b71b87b52ba79681b7a5 100644 (file)
@@ -45,6 +45,7 @@ public class DurationTest {
     assertThat(Duration.create(ONE_HOUR_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1h");
     assertThat(Duration.create(HOURS_IN_DAY * ONE_HOUR_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1d");
     assertThat(Duration.create(ONE_MINUTE).encode(HOURS_IN_DAY)).isEqualTo("1min");
+    assertThat(Duration.create(0).encode(HOURS_IN_DAY)).isEqualTo("0min");
   }
 
   @Test
@@ -54,6 +55,7 @@ public class DurationTest {
     assertThat(Duration.decode("23h", HOURS_IN_DAY)).isEqualTo(Duration.create(23 * ONE_HOUR_IN_MINUTES));
     assertThat(Duration.decode("15d", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES));
     assertThat(Duration.decode("42min", HOURS_IN_DAY)).isEqualTo(Duration.create(42 * ONE_MINUTE));
+    assertThat(Duration.decode("0min", HOURS_IN_DAY)).isEqualTo(Duration.create(0));
 
     assertThat(Duration.decode("25h61min", HOURS_IN_DAY)).isEqualTo(Duration.create(25 * ONE_HOUR_IN_MINUTES + 61));
   }