DatePickerDialog extends AlertDialog implements DatePopup, NumberPicker.OnValueChangeListener { protected Calendar newCalendarFromPicker() { Calendar newCalendar = Calendar.getInstance(); newCalendar.set(yearPicker.getValue() - 543, monthPicker.getValue(), 1); if (dayPicker.getValue() > newCalendar.getActualMaximum(DAY_OF_MONTH)) { dayPicker.setValue(newCalendar.getActualMaximum(DAY_OF_MONTH)); } dayPicker.setMaxValue(newCalendar.getActualMaximum(DAY_OF_MONTH)); newCalendar.set(DAY_OF_MONTH, dayPicker.getValue()); return newCalendar; } DatePickerDialog(Context context);  DatePickerDialog(Context context, DatePickerCallback datePickerCallback);  DatePickerDialog(Context context, Calendar calendar, DatePickerCallback datePickerCallback); final void updateDate(Calendar calendar); @Override void updateDate(int year, int month, int dayOfMonth); @Override int getYear(); @Override int getMonth(); @Override int getDayOfMonth(); @Override void setMaxDate(int year, int month, int dayOfMonth); @Override void setMinDate(int year, int month, int dayOfMonth); @Override void setCallback(DatePickerCallback callback); void setMaxDateIsToday(); void setMaxDate(Calendar maxDate); void setMinDateIsToday(); void setMinDate(Calendar minDate); @Override void show(int year, int month, int dayOfMonth); @Override void show(Calendar calendar); @Override void setPopupTitle(String title); @Override void onValueChange(NumberPicker numberPicker, int i, int i1);  }
@Test public void testCalendarFromPicker() throws Exception { datePickerDialog.yearPicker.setValue(2016 + 543); datePickerDialog.monthPicker.setValue(MARCH); datePickerDialog.dayPicker.setValue(31); Calendar newCalendar = datePickerDialog.newCalendarFromPicker(); assertEquals(31, newCalendar.get(DAY_OF_MONTH)); assertEquals(MARCH, newCalendar.get(MONTH)); assertEquals(2016, newCalendar.get(YEAR)); assertEquals(31, newCalendar.getActualMaximum(DAY_OF_MONTH)); datePickerDialog.monthPicker.setValue(FEBRUARY); newCalendar = datePickerDialog.newCalendarFromPicker(); assertEquals(29, newCalendar.get(DAY_OF_MONTH)); }