### Question:
DateOrDatetimeEditor extends PropertyEditorSupport { @Override public void setAsText(String asString) throws IllegalArgumentException { if (StringUtils.isEmpty(asString)) { setValue(null); return; } try { setValue(Context.getDateTimeFormat().parse(asString)); } catch (ParseException dateTimeEx) { try { setValue(Context.getDateFormat().parse(asString)); } catch (ParseException dateEx) { throw new IllegalArgumentException(dateTimeEx); } } }  @Override void setAsText(String asString); @Override String getAsText();  }### Answer:
@Test public void setAsText_shouldHandleDate() throws ParseException { ed.setAsText("27/10/2011"); Assert.assertEquals(ymdhm.parse("2011-10-27 00:00"), ed.getValue()); }
@Test public void setAsText_shouldHandleDateAndTime() throws ParseException { ed.setAsText("27/10/2011 17:59"); Assert.assertEquals(ymdhm.parse("2011-10-27 17:59"), ed.getValue()); }
@Test(expected = IllegalArgumentException.class) public void setAsText_shouldFailOnPartialDate() { ed.setAsText("27/10"); }
@Test(expected = IllegalArgumentException.class) public void setAsText_shouldFailOnPartialDateAndTime() { ed.setAsText("27/10/2011 17"); }
@Test public void setAsText_shouldHandleDate() throws Exception { ed.setAsText("27/10/2011"); Assert.assertEquals(ymdhm.parse("2011-10-27 00:00"), ed.getValue()); }
@Test public void setAsText_shouldHandleDateAndTime() throws Exception { ed.setAsText("27/10/2011 17:59"); Assert.assertEquals(ymdhm.parse("2011-10-27 17:59"), ed.getValue()); }
@Test(expected = IllegalArgumentException.class) public void setAsText_shouldFailOnPartialDate() throws Exception { ed.setAsText("27/10"); }
@Test(expected = IllegalArgumentException.class) public void setAsText_shouldFailOnPartialDateAndTime() throws Exception { ed.setAsText("27/10/2011 17"); }