### Question:
KmlUtil { public static String substituteProperties(String template, KmlPlacemark placemark) { StringBuffer sb = new StringBuffer(); Pattern pattern = Pattern.compile("\\$\\[(.+?)]"); Matcher matcher = pattern.matcher(template); while (matcher.find()) { String property = matcher.group(1); String value = placemark.getProperty(property); if (value != null) { matcher.appendReplacement(sb, value); } } matcher.appendTail(sb); return sb.toString(); }  static String substituteProperties(String template, KmlPlacemark placemark);  }### Answer:
@Test public void testSubstituteProperties() { Map<String, String> properties = new HashMap<>(); properties.put("name", "Bruce Wayne"); properties.put("description", "Batman"); properties.put("Snippet", "I am the night"); KmlPlacemark placemark = new KmlPlacemark(null, null, null, properties); String result1 = KmlUtil.substituteProperties("$[name] is my name", placemark); assertEquals("Bruce Wayne is my name", result1); String result2 = KmlUtil.substituteProperties("Also known as $[description]", placemark); assertEquals("Also known as Batman", result2); String result3 = KmlUtil.substituteProperties("I say \"$[Snippet]\" often", placemark); assertEquals("I say \"I am the night\" often", result3); String result4 = KmlUtil.substituteProperties("My address is $[address]", placemark); assertEquals("When property doesn't exist, placeholder is left in place", "My address is $[address]", result4); }