### Question:
DatePM extends TextPM implements IDatePM { public Date getDate() throws ConversionException { if (isEmpty()) { return null; } String str = getText(); ParsePosition posInOut = new ParsePosition(0); Date result = (Date)format.parseObject(str, posInOut); if (posInOut.getIndex() == str.length()) { return result; } else { throw new ConversionException(); } } DatePM(); static synchronized DateFormatProvider getDefaultDateFormatProvider(); static synchronized void setDefaultDateFormatProvider(DateFormatProvider provider); DateFormat getFormat(); void setFormat(DateFormat newFormat); Date getDate(); void setDate(Date date); void setDefaultDate(Date date); @Override Comparable<?> getComparable();  }### Answer:
@Test public void testValidate() { DatePM model = new DatePM(); model.setText("14.01.1971"); assertEquals("pM.isValid()", true, model.isValid()); model.setText("31.02"); assertEquals("pM.isValid()", false, model.isValid()); model.setText("aaa"); assertEquals("pM.isValid()", false, model.isValid()); try { model.getDate(); fail("ecpected ConversionException"); } catch (ConversionException ex) { } model.setText("14.01.1971a"); assertEquals("pM.isValid()", false, model.isValid()); try { model.getDate(); fail("ecpected ConversionException"); } catch (ConversionException ex) { } }
@Test public void validateTimeSpan() { final DatePM from = new DatePM(); final DatePM to = new DatePM(); final ValidationRule v = new ValidationRule() { public ValidationState validate() { try { Date fromDate = from.getDate(); Date toDate = to.getDate(); if (fromDate != null && toDate != null && fromDate.before(toDate) == false) { return new ValidationState("from-Date has to be before to-Date"); } else { return null; } } catch (ConversionException ex) { return null; } } }; from.getValidator().add(v); to.getValidator().add(v); from.setText("14.01.2001"); to.setText("10.03.1995"); assertEquals("from.isValid()", true, from.isValid()); assertEquals("to.isValid()", false, to.isValid()); class MyModel extends AbstractPM { final DatePM from = new DatePM(); final DatePM to = new DatePM(); final ValidationRule rule = new ValidationRule() { public ValidationState validate() { try { Date fromDate = from.getDate(); Date toDate = to.getDate(); if (fromDate != null && toDate != null && fromDate.before(toDate) == false) { return new ValidationState("from-Date has to be before to-Date"); } else { return null; } } catch (ConversionException ex) { return null; } } }; public MyModel() { PMManager.setup(this); from.getValidator().add(rule); to.getValidator().add(rule); from.setText("14.01.2001"); to.setText("10.03.1995"); } } MyModel model = new MyModel(); assertEquals("model.from.isValid()", false, model.from.isValid()); assertEquals("model.to.isValid()", false, model.to.isValid()); model.from.setText("14.01.1971"); model.to.setText("10.03.1972"); assertEquals("model.from.isValid()", true, model.from.isValid()); assertEquals("model.to.isValid()", true, model.to.isValid()); model.from.setText("14.01"); assertEquals("model.from.isValid()", false, model.from.isValid()); assertEquals("model.to.isValid()", true, model.to.isValid()); model.to.setText("10.03"); assertEquals("model.from.isValid()", false, model.from.isValid()); assertEquals("model.sto.isValid()", false, model.to.isValid()); }