### Question:
DatePM extends TextPM implements IDatePM { public void setFormat(DateFormat newFormat) { Format oldFormat = format; if (oldFormat == newFormat) { return; } boolean doReformat; Date oldValue = null; try { oldValue = getDate(); doReformat = true; } catch (ConversionException ex) { doReformat = false; } format = (DateFormat)newFormat.clone(); getPropertyChangeSupport().firePropertyChange("format", oldFormat, newFormat); revalidate(); if (doReformat) { setDate(oldValue); } } 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 setGermanFormat() { Locale.setDefault(Locale.GERMANY); DatePM pm = new DatePM(); pm.setText("14.01.2011"); assertEquals("pm.isValid()", true, pm.isValid()); DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); pm.setFormat(format); assertEquals("1/14/11", pm.getText()); }
@Test public void setUSFormat2() { Locale.setDefault(Locale.US); DatePM pm = new DatePM(); pm.setText("Jan 14, 2011"); assertEquals("pm.isValid()", true, pm.isValid()); Locale.setDefault(Locale.GERMAN); DateFormat format = DateFormat.getDateInstance(); pm.setFormat(format); assertEquals("14.01.2011", pm.getText()); }
@Test public void setFormatWithInvalidDate() { Locale.setDefault(Locale.GERMANY); DatePM pm = new DatePM(); pm.setText("14.0"); DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US); pm.setFormat(format); assertEquals("14.0", pm.getText()); }