### Question:
NameTemplate extends LayoutTemplate { public String format(PersonName personName) { List<String> personNameLines = new ArrayList<>(); List<List<Map<String, String>>> lines = getLines(); String layoutToken = getLayoutToken(); try { for (List<Map<String, String>> line : lines) { StringBuilder nameLine = new StringBuilder(); Boolean hasToken = false; for (Map<String, String> lineToken : line) { if (lineToken.get("isToken").equals(layoutToken)) { String tokenValue = BeanUtils.getProperty(personName, lineToken.get("codeName")); if (StringUtils.isNotBlank(tokenValue)) { hasToken = true; nameLine.append(tokenValue); } } else { nameLine.append(lineToken.get("displayText")); } } String nameLineString = nameLine.toString(); if (StringUtils.isNotBlank(nameLineString) && hasToken) { personNameLines.add(nameLineString); } } return StringUtils.join(personNameLines, " "); } catch (Exception e) { throw new APIException("Unable to format personName " + personName.getId() + " using name template", e); } }  @Override String getLayoutToken(); @Override String getNonLayoutToken(); String format(PersonName personName); @Override LayoutSupport<?> getLayoutSupportInstance();  }### Answer:
@Test public void shouldProperlyFormatName() { NameTemplate nameTemplate = new NameTemplate(); List<String> lineByLineFormat = new ArrayList<>(); lineByLineFormat.add("givenName"); lineByLineFormat.add("familyName"); nameTemplate.setLineByLineFormat(lineByLineFormat); Map<String, String> nameMappings = new HashMap<>(); nameMappings.put("givenName", "givenName"); nameMappings.put("familyName", "familyName"); nameTemplate.setNameMappings(nameMappings); Map<String, String> sizeMappings = new HashMap<>(); sizeMappings.put("givenName", "30"); sizeMappings.put("familyName", "30"); nameTemplate.setSizeMappings(sizeMappings); nameSupport.setLayoutTemplates(Collections.singletonList(nameTemplate)); PersonName personName = new PersonName(); personName.setGivenName("Mark"); personName.setFamilyName("Goodrich"); Assert.assertEquals("Mark Goodrich", nameTemplate.format(personName)); }
@Test public void shouldProperlyFormatNameWithNonTokens() { NameTemplate nameTemplate = new NameTemplate(); List<String> lineByLineFormat = new ArrayList<>(); lineByLineFormat.add("familyName,"); lineByLineFormat.add("givenName"); lineByLineFormat.add("\"middleName\""); nameTemplate.setLineByLineFormat(lineByLineFormat); Map<String, String> nameMappings = new HashMap<>(); nameMappings.put("familyName", "familyName"); nameMappings.put("givenName", "givenName"); nameMappings.put("middleName", "middleName"); nameTemplate.setNameMappings(nameMappings); Map<String, String> sizeMappings = new HashMap<>(); sizeMappings.put("familyName", "30"); sizeMappings.put("givenName", "30"); sizeMappings.put("middleName", "30"); nameTemplate.setSizeMappings(sizeMappings); nameSupport.setLayoutTemplates(Collections.singletonList(nameTemplate)); PersonName personName = new PersonName(); personName.setGivenName("Mark"); personName.setFamilyName("Goodrich"); personName.setMiddleName("Blue State"); Assert.assertEquals("Goodrich, Mark \"Blue State\"", nameTemplate.format(personName)); }