### Question:
DateXarObjectPropertySerializer implements XarObjectPropertySerializer { public static Date parseDate(String source) { SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); try { return format.parse(source); } catch (ParseException e) { SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", source, DEFAULT_FORMAT, sdfOld.toPattern()); try { return sdfOld.parse(source); } catch (ParseException exception) { LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", source, sdfOld.toPattern()); return new Date(); } } }  static Date parseDate(String source); static String serializeDate(Object date); @Override Object read(XMLStreamReader reader); @Override void write(XMLStreamWriter writer, Object value); static final String DEFAULT_FORMAT; }### Answer:
@Test void parseDate() throws ParseException { Date newDate = new Date(); DateFormat format = new SimpleDateFormat(DateXarObjectPropertySerializer.DEFAULT_FORMAT); String string = format.format(newDate); Date formattedDate = format.parse(string); assertEquals(formattedDate, DateXarObjectPropertySerializer.parseDate(string)); }
@Test void parseDateOld() throws ParseException { Date newDate = new Date(); DateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); String string = format.format(newDate); Date formattedDate = format.parse(string); assertEquals(formattedDate, DateXarObjectPropertySerializer.parseDate(string)); assertEquals( "Failed to parse date [" + string + "] using format [yyyy-MM-dd HH:mm:ss.S]." + " Trying again with format [EEE MMM d HH:mm:ss z yyyy].", this.logCapture.getLogEvent(0).getFormattedMessage()); }
@Test void parseDateInvalid() { Date newDate = new Date(); assertTrue(DateXarObjectPropertySerializer.parseDate("not date").after(newDate)); assertEquals( "Failed to parse date [not date] using format [yyyy-MM-dd HH:mm:ss.S]." + " Trying again with format [EEE MMM d HH:mm:ss z yyyy].", this.logCapture.getLogEvent(0).getFormattedMessage()); assertEquals("Failed to parse date [not date] using format [EEE MMM d HH:mm:ss z yyyy]." + " Defaulting to the current date.", this.logCapture.getLogEvent(1).getFormattedMessage()); }