### Question:
PersonNamesDefaultNamePropertyParser implements PropertyParser { @Override public Comparable<?> parseForSort(String value) { if (value != null) { try { PersonNames personNames = readPersonNames(value); String defaultName = personNames.defaultName().getSortName(); if (StringUtils.isBlank(defaultName)) { return null; } return defaultName; } catch (IOException e) { LOG.error("Cannot parse '{}' as PersonNames", value); LOG.error("Exception thrown", e); } } return null; }  @Override String parse(String value); @Override Comparable<?> parseForSort(String value);  }### Answer:
@Test public void parseForSortReturnsAStringThatConsistsOfSortNameVariantOfTheDefaultName() throws JsonProcessingException { PersonNames names = new PersonNames(); PersonName name1 = PersonName.newInstance("forename", "surname"); names.list.add(name1); PersonName name2 = PersonName.newInstance("forename2", "surname2"); names.list.add(name2); String input = new ObjectMapper().writeValueAsString(names); Object value = instance.parseForSort(input); assertThat(value, is(names.defaultName().getSortName())); }
@Test public void parseForSortReturnsNullIfTheInputCannotBeParsed() throws JsonProcessingException { Object value = instance.parseForSort("invalid serialized names"); assertThat(value, is(nullValue())); }
@Test public void parserToRawReturnsNullIfThePersonNamesIsEmpty() throws JsonProcessingException { PersonNames names = new PersonNames(); String input = new ObjectMapper().writeValueAsString(names); Object value = instance.parseForSort(input); assertThat(value, is(nullValue())); }