aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-12-05 08:23:49 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-12-05 08:23:49 +0100
commitf8c1e6e7e7f7aeb5edf325bb819fd33e432f3153 (patch)
treefe4b672fa5f9e50c504cdccff5c6901c5a157739 /sonar-batch
parenta95eb1f87bfb7505d46b3d49f33d5b9a7eed3262 (diff)
downloadsonarqube-f8c1e6e7e7f7aeb5edf325bb819fd33e432f3153.tar.gz
sonarqube-f8c1e6e7e7f7aeb5edf325bb819fd33e432f3153.zip
Fix quality flaws
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DurationLabel.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DurationLabelTest.java22
2 files changed, 19 insertions, 23 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DurationLabel.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DurationLabel.java
index 132d1c12318..e04109ead9d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DurationLabel.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DurationLabel.java
@@ -19,11 +19,13 @@
*/
package org.sonar.batch.bootstrap;
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang.StringUtils;
+
import java.text.MessageFormat;
public class DurationLabel {
- private String prefixAgo = null;
private String suffixAgo = "ago";
private String seconds = "less than a minute";
private String minute = "about a minute";
@@ -38,7 +40,7 @@ public class DurationLabel {
private String years = "{0} years";
public String label(long durationInMillis) {
- double seconds = durationInMillis / 1000;
+ double seconds = durationInMillis / 1000.0;
double minutes = seconds / 60;
double hours = minutes / 60;
double days = hours / 24;
@@ -67,25 +69,19 @@ public class DurationLabel {
time = this.year;
}
- return join(prefixAgo, time, suffixAgo);
+ return join(time, suffixAgo);
}
- public String join(String prefix, String time, String suffix) {
+ @VisibleForTesting
+ String join(String time, String suffix) {
StringBuilder joined = new StringBuilder();
- if (prefix != null && prefix.length() > 0) {
- joined.append(prefix).append(' ');
- }
joined.append(time);
- if (suffix != null && suffix.length() > 0) {
+ if (StringUtils.isNotBlank(suffix)) {
joined.append(' ').append(suffix);
}
return joined.toString();
}
- public String getPrefixAgo() {
- return prefixAgo;
- }
-
public String getSuffixAgo() {
return suffixAgo;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DurationLabelTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DurationLabelTest.java
index 39430928012..1c35d39ba24 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DurationLabelTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DurationLabelTest.java
@@ -38,7 +38,7 @@ public class DurationLabelTest {
public void testAgoSeconds() {
DurationLabel durationLabel = new DurationLabel();
String label = durationLabel.label(now() - System.currentTimeMillis());
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), durationLabel.getSeconds(), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(durationLabel.getSeconds(), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -46,7 +46,7 @@ public class DurationLabelTest {
public void testAgoMinute() {
DurationLabel durationLabel = new DurationLabel();
String label = durationLabel.label(now() - ago(MINUTE));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), durationLabel.getMinute(), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(durationLabel.getMinute(), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -55,7 +55,7 @@ public class DurationLabelTest {
DurationLabel durationlabel = new DurationLabel();
int minutes = 2;
String label = durationlabel.label(now() - ago(minutes * MINUTE));
- String expected = durationlabel.join(durationlabel.getPrefixAgo(),
+ String expected = durationlabel.join(
MessageFormat.format(durationlabel.getMinutes(), minutes), durationlabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -64,7 +64,7 @@ public class DurationLabelTest {
public void testAgoHour() {
DurationLabel durationLabel = new DurationLabel();
String label = durationLabel.label(now() - ago(HOUR));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), durationLabel.getHour(), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(durationLabel.getHour(), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -73,7 +73,7 @@ public class DurationLabelTest {
DurationLabel durationLabel = new DurationLabel();
long hours = 3;
String label = durationLabel.label(now() - ago(hours * HOUR));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), MessageFormat.format(durationLabel.getHours(), hours), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(MessageFormat.format(durationLabel.getHours(), hours), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -81,7 +81,7 @@ public class DurationLabelTest {
public void testAgoDay() {
DurationLabel durationLabel = new DurationLabel();
String label = durationLabel.label(now() - ago(30 * HOUR));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), durationLabel.getDay(), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(durationLabel.getDay(), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -90,7 +90,7 @@ public class DurationLabelTest {
DurationLabel durationLabel = new DurationLabel();
long days = 4;
String label = durationLabel.label(now() - ago(days * DAY));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), MessageFormat.format(durationLabel.getDays(), days), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(MessageFormat.format(durationLabel.getDays(), days), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -98,7 +98,7 @@ public class DurationLabelTest {
public void testAgoMonth() {
DurationLabel durationLabel = new DurationLabel();
String label = durationLabel.label(now() - ago(35 * DAY));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), durationLabel.getMonth(), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(durationLabel.getMonth(), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -107,7 +107,7 @@ public class DurationLabelTest {
DurationLabel durationLabel = new DurationLabel();
long months = 2;
String label = durationLabel.label(now() - ago(months * MONTH));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), MessageFormat.format(durationLabel.getMonths(), months), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(MessageFormat.format(durationLabel.getMonths(), months), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -115,7 +115,7 @@ public class DurationLabelTest {
public void testYearAgo() {
DurationLabel durationLabel = new DurationLabel();
String label = durationLabel.label(now() - ago(14 * MONTH));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), durationLabel.getYear(), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(durationLabel.getYear(), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}
@@ -124,7 +124,7 @@ public class DurationLabelTest {
DurationLabel durationLabel = new DurationLabel();
long years = 7;
String label = durationLabel.label(now() - ago(years * YEAR));
- String expected = durationLabel.join(durationLabel.getPrefixAgo(), MessageFormat.format(durationLabel.getYears(), years), durationLabel.getSuffixAgo());
+ String expected = durationLabel.join(MessageFormat.format(durationLabel.getYears(), years), durationLabel.getSuffixAgo());
assertThat(label).isEqualTo(expected);
}