@Test public void GIVEN_null_date_component_WHEN_mmddyyyy_formatting_requested_THEN_returns_empty_date_value() { testee = new DateFormatter(null, 12, 31); assertEquals("--/--/----", testee.format(DateFormat.MM_DD_YYYY)); testee = new DateFormatter(2013, null, 31); assertEquals("--/--/----", testee.format(DateFormat.MM_DD_YYYY)); testee = new DateFormatter(2013, 12, null); assertEquals("--/--/----", testee.format(DateFormat.MM_DD_YYYY)); }
public String format(DateFormat dateFormat) { String formatted; if (year != null && month != null && day != null) { if (dateFormat == YYYY_MM_DD) { formatted = String.format(Locale.US, "%1$04d/%2$02d/%3$02d", year, month, day); } else if (dateFormat == DateFormat.DD_MM_YYYY) { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", day, month, year); } else { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", month, day, year); } } else { if (dateFormat == YYYY_MM_DD) { formatted = "----/--/--"; } else { formatted = "--/--/----"; } } return formatted; }
DateFormatter { public String format(DateFormat dateFormat) { String formatted; if (year != null && month != null && day != null) { if (dateFormat == YYYY_MM_DD) { formatted = String.format(Locale.US, "%1$04d/%2$02d/%3$02d", year, month, day); } else if (dateFormat == DateFormat.DD_MM_YYYY) { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", day, month, year); } else { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", month, day, year); } } else { if (dateFormat == YYYY_MM_DD) { formatted = "----/--/--"; } else { formatted = "--/--/----"; } } return formatted; } }
DateFormatter { public String format(DateFormat dateFormat) { String formatted; if (year != null && month != null && day != null) { if (dateFormat == YYYY_MM_DD) { formatted = String.format(Locale.US, "%1$04d/%2$02d/%3$02d", year, month, day); } else if (dateFormat == DateFormat.DD_MM_YYYY) { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", day, month, year); } else { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", month, day, year); } } else { if (dateFormat == YYYY_MM_DD) { formatted = "----/--/--"; } else { formatted = "--/--/----"; } } return formatted; } DateFormatter(Integer year, Integer month, Integer day); }
DateFormatter { public String format(DateFormat dateFormat) { String formatted; if (year != null && month != null && day != null) { if (dateFormat == YYYY_MM_DD) { formatted = String.format(Locale.US, "%1$04d/%2$02d/%3$02d", year, month, day); } else if (dateFormat == DateFormat.DD_MM_YYYY) { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", day, month, year); } else { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", month, day, year); } } else { if (dateFormat == YYYY_MM_DD) { formatted = "----/--/--"; } else { formatted = "--/--/----"; } } return formatted; } DateFormatter(Integer year, Integer month, Integer day); String format(DateFormat dateFormat); }
DateFormatter { public String format(DateFormat dateFormat) { String formatted; if (year != null && month != null && day != null) { if (dateFormat == YYYY_MM_DD) { formatted = String.format(Locale.US, "%1$04d/%2$02d/%3$02d", year, month, day); } else if (dateFormat == DateFormat.DD_MM_YYYY) { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", day, month, year); } else { formatted = String.format(Locale.US, "%1$02d/%2$02d/%3$04d", month, day, year); } } else { if (dateFormat == YYYY_MM_DD) { formatted = "----/--/--"; } else { formatted = "--/--/----"; } } return formatted; } DateFormatter(Integer year, Integer month, Integer day); String format(DateFormat dateFormat);  }