@Test public void GIVEN_null_time_component_WHEN_12_hour_formatting_requested_THEN_returns_empty_time_value() { testee = new TimeFormatter(null, 59); assertEquals("--:-- --", testee.format(TimeFormat.HOUR_12)); testee = new TimeFormatter(23, null); assertEquals("--:-- --", testee.format(TimeFormat.HOUR_12)); }
public String format(TimeFormat timeFormat) { String formatted; if (hour != null && minute != null) { if (timeFormat == HOUR_24) { formatted = String.format(Locale.US, "%1$02d:%2$02d", hour, minute); } else { formatted = String.format(Locale.US, "%1$01d:%2$02d %3$2s", getTwelveHour(hour), minute, getTwelveHourPeriod(hour)); } } else { if (timeFormat == HOUR_24) { formatted = "--:--"; } else { formatted = "--:-- --"; } } return formatted; }
TimeFormatter { public String format(TimeFormat timeFormat) { String formatted; if (hour != null && minute != null) { if (timeFormat == HOUR_24) { formatted = String.format(Locale.US, "%1$02d:%2$02d", hour, minute); } else { formatted = String.format(Locale.US, "%1$01d:%2$02d %3$2s", getTwelveHour(hour), minute, getTwelveHourPeriod(hour)); } } else { if (timeFormat == HOUR_24) { formatted = "--:--"; } else { formatted = "--:-- --"; } } return formatted; } }
TimeFormatter { public String format(TimeFormat timeFormat) { String formatted; if (hour != null && minute != null) { if (timeFormat == HOUR_24) { formatted = String.format(Locale.US, "%1$02d:%2$02d", hour, minute); } else { formatted = String.format(Locale.US, "%1$01d:%2$02d %3$2s", getTwelveHour(hour), minute, getTwelveHourPeriod(hour)); } } else { if (timeFormat == HOUR_24) { formatted = "--:--"; } else { formatted = "--:-- --"; } } return formatted; } TimeFormatter(Integer hour, Integer minute); }
TimeFormatter { public String format(TimeFormat timeFormat) { String formatted; if (hour != null && minute != null) { if (timeFormat == HOUR_24) { formatted = String.format(Locale.US, "%1$02d:%2$02d", hour, minute); } else { formatted = String.format(Locale.US, "%1$01d:%2$02d %3$2s", getTwelveHour(hour), minute, getTwelveHourPeriod(hour)); } } else { if (timeFormat == HOUR_24) { formatted = "--:--"; } else { formatted = "--:-- --"; } } return formatted; } TimeFormatter(Integer hour, Integer minute); String format(TimeFormat timeFormat); }
TimeFormatter { public String format(TimeFormat timeFormat) { String formatted; if (hour != null && minute != null) { if (timeFormat == HOUR_24) { formatted = String.format(Locale.US, "%1$02d:%2$02d", hour, minute); } else { formatted = String.format(Locale.US, "%1$01d:%2$02d %3$2s", getTwelveHour(hour), minute, getTwelveHourPeriod(hour)); } } else { if (timeFormat == HOUR_24) { formatted = "--:--"; } else { formatted = "--:-- --"; } } return formatted; } TimeFormatter(Integer hour, Integer minute); String format(TimeFormat timeFormat);  }