DefaultFormatter implements Formatter { @Override public String getHeaderText(@CalendarType int type, @NonNull LocalDate from, @NonNull LocalDate to) { switch (type) { case CalendarUnit.TYPE_WEEK: return from.toString(weekHeaderFormatter); case CalendarUnit.TYPE_MONTH: return from.toString(monthHeaderFormatter); default: throw new IllegalStateException("Unknown calendar type"); } } DefaultFormatter();  DefaultFormatter(@NonNull String dayPattern, @NonNull String weekPattern, @NonNull String monthPattern); @Override String getDayName(@NonNull LocalDate date); @Override String getHeaderText(@CalendarType int type, @NonNull LocalDate from, @NonNull LocalDate to);  }
@Test public void testGetHeaderTextWeek() throws Exception { String headerText = formatter.getHeaderText(CalendarUnit.TYPE_WEEK, new LocalDate(2015, 4, 20), new LocalDate(2015, 4, 26)); assertEquals("week 17", headerText); }
@Test public void testGetHeaderTextMonth() throws Exception { String headerText = formatter.getHeaderText(CalendarUnit.TYPE_MONTH, new LocalDate(2015, 4, 1), new LocalDate(2015, 4, 30)); assertEquals("April 2015", headerText); }
@Test(expected = RuntimeException.class) public void testGetHeaderTextInvalidType() throws Exception { formatter.getHeaderText(3, new LocalDate(2015, 4, 1), new LocalDate(2015, 4, 30)); }