From: Julien Lancelot Date: Tue, 11 Mar 2014 08:17:01 +0000 (+0100) Subject: SONAR-4767 On mode DAYS, do not display null when there's no date X-Git-Tag: 4.3~494 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6701b7aa2f66e4eec8449ddf7020fcea4e7f0c27;p=sonarqube.git SONAR-4767 On mode DAYS, do not display null when there's no date --- diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 127303eec2d..5d64d7b8e2a 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -218,8 +218,10 @@ new_window=New window no_data=No data no_lines_match_your_filter_criteria=No lines match your filter criteria. no_results=No results -over_x_days=over {0} days ({1}) +over_x_days=over {0} days over_x_days.short={0} days +over_x_days_detailed=over {0} days ({1}) +over_x_days_detailed.short={0} days ({1}) page_size=Page size paging_first=First paging_last=Last diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index f4f8be6d18a..b39eeaf916e 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -27,6 +27,8 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; +import javax.annotation.Nullable; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -74,10 +76,13 @@ public class Periods implements BatchExtension, ServerComponent { return label(mode, param, convertDate(date), true); } - private String label(String mode, String param, String date, boolean shortLabel) { + private String label(String mode, @Nullable String param, @Nullable String date, boolean shortLabel) { String label; if (CoreProperties.TIMEMACHINE_MODE_DAYS.equals(mode)) { - label = label("over_x_days", shortLabel, param, date); + label = label("over_x_days", shortLabel, param); + if (date != null) { + label = label("over_x_days_detailed", shortLabel, param, date); + } } else if (CoreProperties.TIMEMACHINE_MODE_VERSION.equals(mode)) { label = label("since_version", shortLabel, param); if (date != null) { diff --git a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java index b70b56f2719..a312ee40626 100644 --- a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java @@ -62,13 +62,12 @@ public class PeriodsTest { @Test public void label_of_duration_in_days() { - Date date = new Date(); when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(date); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); - verify(i18n).message(any(Locale.class), eq("over_x_days"), isNull(String.class), eq(param), anyString()); + verify(i18n).message(any(Locale.class), eq("over_x_days_detailed"), isNull(String.class), eq(param), anyString()); } @Test @@ -78,7 +77,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.abbreviation(snapshot, periodIndex); - verify(i18n).message(any(Locale.class), eq("over_x_days.short"), isNull(String.class), eq(param), anyString()); + verify(i18n).message(any(Locale.class), eq("over_x_days_detailed.short"), isNull(String.class), eq(param), anyString()); } @Test @@ -191,7 +190,7 @@ public class PeriodsTest { settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, days); periods.label(periodIndex); - verify(i18n).message(any(Locale.class), eq("over_x_days"), isNull(String.class), eq(days), anyString()); + verify(i18n).message(any(Locale.class), eq("over_x_days"), isNull(String.class), eq(days)); } @Test