DateField extends TextField implements DatePickerDialog.OnDateSetListener, DialogInterface.OnClickListener, View.OnTouchListener { protected Calendar getDate() { try { Calendar calendar = Calendar.getInstance(); calendar.setTime(getDateFormatter().parse(getText())); return calendar; } catch (Exception e) { return null; } } DateField(Context context);  DateField(Context context, AttributeSet attrs); @Override boolean onTouch(View v, MotionEvent event); @Override void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth); @Override void onClick(DialogInterface dialog, int which);  }
@Test public void testNullDateWhenTextIsEmpty() { view.setText(""); assertNull(view.getDate()); }
@Test public void testNullDateWhenTextIsInvalid() { view.setText("Is this a date?"); assertNull(view.getDate()); }