VelocityWrapper { public String merge(Map<String, Object> contextMap, String templateFileName) { updateContext(contextMap); Template template = velocityEngine.getTemplate(templateFileName); StringWriter writer = new StringWriter(); template.merge(context, writer); return writer.toString(); } VelocityWrapper();  VelocityWrapper(Properties properties); String merge(Map<String, Object> contextMap, String templateFileName);  }
@Test public void canMerge() throws Exception { VelocityWrapper wrapper = new VelocityWrapper(); Map<String, Object> contextMap = new HashMap<>(); contextMap.put("key1", "dummy1"); contextMap.put("key2", "dummy2"); contextMap.put("key3", "dummy3"); String mergedString = wrapper.merge(contextMap, "test-velocity3.vm"); String mergedStringClean = mergedString.replaceAll("\r", ""); assertThat(mergedStringClean, equalTo("<?xml version=\"1.0\"?>\n" + "\n<test testAttr=\"$test\">\n" + " <contents>\n" + " <key>dummy1</key>\n" + " <key>dummy2</key>\n" + " <key>dummy3</key>\n" + " </contents>\n" + "</test>")); }