### Question:
StringTemplateHelper { public void writeTemplate( Writer out, Consumer<StringTemplate> parameterSetter) throws TemplateException { Preconditions.checkNotNull(out); Preconditions.checkNotNull(parameterSetter); StringTemplate stringTemplate = group.getInstanceOf(templatePath); try { parameterSetter.accept(stringTemplate); stringTemplate.write(new AutoIndentWriter(out)); } catch (IOException e) { throw new TemplateException("Failed to write template: " + e, e); } } StringTemplateHelper(
      Class<?> templateContextClass,
      String templateName,
      boolean cacheTemplates); void writeTemplate(
      Writer out,
      Consumer<StringTemplate> parameterSetter);  }### Answer:
@Test public void testFillTemplate() throws Exception { StringWriter output = new StringWriter(); templateHelper.writeTemplate(output, template -> { template.setAttribute("header", "Prices"); template.setAttribute("items", Arrays.asList( new Item("banana", 50), new Item("car", 2), new Item("jupiter", 200) )); template.setAttribute("footer", "The End"); }); String expected = "Prices\n" + "\n The banana costs $50." + "\n The car costs $2." + "\n The jupiter costs $200.\n" + "\n\nThe End"; assertEquals(expected, output.toString()); }
@Test(expected = CustomException.class) public void testClosureError() throws Exception { templateHelper.writeTemplate(new StringWriter(), template -> { throw new CustomException(); }); }