### Question:
LocalizedTitleDefinitionBuilderImpl implements ResourceDefinitionBuilder { @Override public final ResourceDefinition convert(String data) { data = StringUtils.stripToEmpty(data); Map<String, String> localizedTitles = new TreeMap<String, String>(); String name; String title = ""; final Matcher matcher = NODE_NAME_PATTERN.matcher(data); if (matcher.find() && matcher.groupCount() == 1) { name = StringUtils.stripToEmpty(matcher.group(1)); } else { return null; } final String rawLocalizedTitles = StringUtils.stripToEmpty(NODE_NAME_PATTERN.matcher(data).replaceAll("")); final Matcher localeMatch = LOCALIZED_TITLES_PATTERN.matcher(rawLocalizedTitles); String firstLocale = null; while (localeMatch.find()) { final String locale = StringUtils.stripToEmpty(localeMatch.group(1)); final String localeTitle = StringUtils.stripToEmpty(localeMatch.group(2)); if (firstLocale == null) { firstLocale = locale; } if (DEFAULT_LOCALE_KEY.equals(locale)) { title = localeTitle; } else { localizedTitles.put(locale, localeTitle); } } if (StringUtils.isEmpty(title) && firstLocale != null) { title = localizedTitles.get(firstLocale); } if (StringUtils.isEmpty(title)) { return null; } final BasicResourceDefinition tagData = new BasicResourceDefinition(name); tagData.setTitle(title); tagData.setLocalizedTitles(localizedTitles); return tagData; }  @Override final ResourceDefinition convert(String data); @Override boolean accepts(String data); static final String NAME; }### Answer:
@Test public void convertWithDefault() throws Exception { String data = "default[Default Title] en[English Title] fr[French Title] es[Spanish Title] {{ my-title }}"; Map<String, String> expected = new HashMap<String, String>(); expected.put("en", "English Title"); expected.put("fr", "French Title"); expected.put("es", "Spanish Title"); ResourceDefinition def = builder.convert(data); Map<String, String> actual = def.getLocalizedTitles(); assertEquals("Default Title", def.getTitle()); assertEquals(expected, actual); }
@Test public void convertWithoutDefault() throws Exception { String data = " en[English Title] fr[French Title] es[Spanish Title] {{my-title}} "; Map<String, String> expected = new HashMap<String, String>(); expected.put("en", "English Title"); expected.put("fr", "French Title"); expected.put("es", "Spanish Title"); ResourceDefinition def = builder.convert(data); Map<String, String> actual = def.getLocalizedTitles(); assertEquals("English Title", def.getTitle()); assertEquals(expected, actual); }