### Question:
MessageFormatterMethod implements TemplateMethodModelEx { @Override public Object exec(List list) throws TemplateModelException { if (list.size() >= 1) { List<Object> resolved = resolve(list.subList(1, list.size())); String key = list.get(0).toString(); return new MessageFormat(messages.getProperty(key,key),locale).format(resolved.toArray()); } else { return null; } } MessageFormatterMethod(Locale locale, Properties messages); @Override Object exec(List list);  }### Answer:
@Test public void test() throws TemplateModelException { Locale locale = Locale.US; Properties properties = new Properties(); properties.setProperty("backToApplication", "Back to application"); properties.setProperty("backToClient", "Back to {0}"); properties.setProperty("client_admin-console", "Admin Console"); properties.setProperty("realm_example-realm", "Example Realm"); MessageFormatterMethod fmt = new MessageFormatterMethod(locale, properties); String msg = (String) fmt.exec(Arrays.asList("backToClient", "${client_admin-console}")); Assert.assertEquals("Back to Admin Console", msg); msg = (String) fmt.exec(Arrays.asList("backToClient", "client_admin-console")); Assert.assertEquals("Back to client_admin-console", msg); msg = (String) fmt.exec(Arrays.asList("backToClient", "client '${client_admin-console}' from '${realm_example-realm}'.")); Assert.assertEquals("Back to client 'Admin Console' from 'Example Realm'.", msg); }