@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())); }
@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; }
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; } }
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; }  }
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); }
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);  }