TemplateInjector { public String injectToTemplate(String template, Object scope) { Mustache mustache = mustacheFactoryUnescapeHtml.compile(new StringReader(template), "template"); StringWriter result = new StringWriter(); try { mustache.execute(result, new Object[] { scope, singletonMap("lowercase", lowercaseFunction) }).flush(); return result.toString(); } catch (IOException e) { String msg = String.format("Failed to inject values to template template=%s, scope=%s", template, scope); logger.warn(msg, e); throw new RuntimeException(msg, e); } }  String injectToTemplate(String template, Object scope);  }
@Test public void testLowercaseFunction() { String varName = "testVar"; String varValue = "testVarValue"; String template = String.format("{{#lowercase}}{{%s}}{{/lowercase}}", varName); String result = templateInjector.injectToTemplate(template, singletonMap(varName, varValue)); assertThat(result).isEqualTo(varValue.toLowerCase()); }