GroovyTemplateFactory implements TemplateFactory<PreparedGroovyTemplate> { @Override public PreparedGroovyTemplate prepareTemplate(String templateText) throws HL7TemplateException { try { return new PreparedGroovyTemplate(templateEngine.createTemplate(templateText)); } catch (Exception ex) { throw new HL7TemplateException(ex); } } GroovyTemplateFactory(); @Override PreparedGroovyTemplate prepareTemplate(String templateText);  }
@Test public void testEvaluatingTemplateWithNullBindings() throws Exception { String evaluated = factory.prepareTemplate("Easy as ${ [ 1, 2, 3 ].join(', ') }").evaluate(null); Assert.assertEquals("Easy as 1, 2, 3", evaluated); }
@Test public void testEvaluatingTemplateWithBindings() throws Exception { Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("list", Arrays.asList("1", "2", "3")); String evaluated = factory.prepareTemplate("Easy as ${ list.join(', ') }").evaluate(bindings); Assert.assertEquals("Easy as 1, 2, 3", evaluated); }
@Test(expected=HL7TemplateException.class) public void testFailureIfTemplateRefersToMissingProperties() throws Exception { Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("list", Arrays.asList("1", "2", "3")); factory.prepareTemplate("Easy as ${ wrongName.join(', ') }").evaluate(bindings); }