### Question:
ChangeDatePropertyParser implements PropertyParser { @Override public String parse(String value) { if (value != null) { try { long timeStamp = readTimeStamp(value); Date date = new Date(timeStamp); return new SimpleDateFormat("yyyyMMdd").format(date); } catch (IOException e) { LOG.error("Cannot parse '{}' as Change", value); LOG.error("Exception thrown", e); } } return null; } ChangeDatePropertyParser(); @Override String parse(String value); @Override Comparable<?> parseForSort(String value); static final Logger LOG; }### Answer:
@Test public void parseReturnsAFormattedYearMonthAndDateIfTheInputIsValid() throws JsonProcessingException { long timeStampOnJan20th2016 = 1453290593000L; Change change = new Change(timeStampOnJan20th2016, "user", "vre"); String changeString = new ObjectMapper().writeValueAsString(change); String result = instance.parse(changeString); assertThat(result, is(equalTo("20160120"))); }
@Test public void parseReturnsNullIfTheInputCannotBeParsed() { String output = instance.parse("notASerializedChange"); assertThat(output, is(nullValue())); }