### Question:
FieldTemplateProcessor implements DocumentProcessor { @Override public Document[] processDocument(Document document) { VelocityContext velocityContext = new VelocityContext(document.asMap()); List<String> values = document.removeAll(templateField); for (String value : values) { StringWriter writer = new StringWriter(); engine.evaluate(velocityContext, writer, document.getId(), value); document.put(templateField, writer.toString()); } return new Document[]{document}; }  @Override String getName(); @Override Document[] processDocument(Document document); void setName(String name); void setTemplateField(String templateField);  }### Answer:
@Test public void testProcessSingleTemplateValue() { List<String> strings = new ArrayList<>(); strings.add("This is all $foobar[0]"); expect(docMock.removeAll("templ")).andReturn(strings); Map<String, Collection<String>> map = new HashMap<>(); map.put("foobar", Collections.singletonList("good")); expect(docMock.getId()).andReturn("bar"); expect(docMock.asMap()).andReturn(map); expect(docMock.put("templ", "This is all good")).andReturn(true); replay(); FieldTemplateProcessor proc = new FieldTemplateProcessor.Builder().named("foo").withTemplatesIn("templ").build(); proc.processDocument(docMock); }
@Test public void testProcessMultipleTemplateValue() { List<String> strings = new ArrayList<>(); strings.add("This is all $foobar[0]."); strings.add("I like $foobar[1]."); expect(docMock.removeAll("templ")).andReturn(strings); Map<String, Collection<String>> map = new HashMap<>(); map.put("foobar", Arrays.asList("good", "pie")); expect(docMock.getId()).andReturn("bar").anyTimes(); expect(docMock.asMap()).andReturn(map); expect(docMock.put("templ", "This is all good.")).andReturn(true); expect(docMock.put("templ", "I like pie.")).andReturn(true); replay(); FieldTemplateProcessor proc = new FieldTemplateProcessor.Builder().named("foo").withTemplatesIn("templ").build(); proc.processDocument(docMock); }