From f8c1e6e7e7f7aeb5edf325bb819fd33e432f3153 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 5 Dec 2012 08:23:49 +0100 Subject: [PATCH] Fix quality flaws --- .../sonar/batch/bootstrap/DurationLabel.java | 20 +++++++---------- .../batch/bootstrap/DurationLabelTest.java | 22 +++++++++---------- .../java/org/sonar/api/CoreProperties.java | 7 ++++++ 3 files changed, 26 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); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index b5231cb8758..7c5c07df2b8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -371,4 +371,11 @@ public interface CoreProperties { * @since 3.4 */ String FORCE_ANALYSIS = "sonar.forceAnalysis"; + + /** + * @deprecated replaced in v3.4 by properties specific to languages, for example sonar.java.coveragePlugin + * See http://jira.codehaus.org/browse/SONARJAVA-39 for more details. + */ + @Deprecated + String CORE_COVERAGE_PLUGIN_PROPERTY = "sonar.core.codeCoveragePlugin"; } -- 2.39.5