SafeCalendar extends GregorianCalendar { @Override public void set(int field, int value) { super.set(field, value); if (field == DAY_OF_YEAR) super.complete(); } SafeCalendar();  SafeCalendar(int year);  SafeCalendar(int year, int month);  SafeCalendar(int year, int month, int day);  SafeCalendar(int year, int month, int day, int hour, int minute);  SafeCalendar(int year, int month, int day, int hour, int minute, int second);  SafeCalendar(Locale locale);  SafeCalendar(TimeZone timezone);  SafeCalendar(TimeZone timezone, Locale locale); @Override String toString(); boolean isEmpty(); @Override void set(int field, int value); static final SafeCalendar EMPTY; }
@SuppressWarnings("MagicNumber") @Test public void testSet() throws Exception { calendar.set(Calendar.DAY_OF_YEAR, 53); assertThat(calendar.get(Calendar.MONTH)).isEqualTo(Calendar.FEBRUARY); assertThat(calendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(22); assertThat(calendar.get(Calendar.HOUR)).isEqualTo(0); assertThat(calendar.get(Calendar.YEAR)).isEqualTo(1970); }