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;
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) {
@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
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
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