@Test(expected = VelocityTemplateParsingException.class) public void shouldThrowExceptionIfTemplateIsMalformed() throws Exception { try (FileInputStream template = loadFile(INCORRECT_TEMPLATE)) { when(settingsFacade.getRawConfig(INCORRECT_TEMPLATE)).thenReturn(template); parser.mergeTemplateIntoString(INCORRECT_TEMPLATE, params); } finally { verify(settingsFacade).getRawConfig(INCORRECT_TEMPLATE); } }
public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException { try (InputStream is = settingsFacade.getRawConfig(templateFilename)) { StringReader reader = new StringReader(IOUtils.toString(is)); SimpleNode node = rs.parse(reader, templateFilename); Template template = new Template(); template.setRuntimeServices(rs); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(new VelocityContext(params), writer); return writer.toString(); } catch (ParseException|IOException e) { throw new VelocityTemplateParsingException("Couldn't merge template into string", e); } }
VelocityTemplateParser { public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException { try (InputStream is = settingsFacade.getRawConfig(templateFilename)) { StringReader reader = new StringReader(IOUtils.toString(is)); SimpleNode node = rs.parse(reader, templateFilename); Template template = new Template(); template.setRuntimeServices(rs); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(new VelocityContext(params), writer); return writer.toString(); } catch (ParseException|IOException e) { throw new VelocityTemplateParsingException("Couldn't merge template into string", e); } } }
VelocityTemplateParser { public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException { try (InputStream is = settingsFacade.getRawConfig(templateFilename)) { StringReader reader = new StringReader(IOUtils.toString(is)); SimpleNode node = rs.parse(reader, templateFilename); Template template = new Template(); template.setRuntimeServices(rs); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(new VelocityContext(params), writer); return writer.toString(); } catch (ParseException|IOException e) { throw new VelocityTemplateParsingException("Couldn't merge template into string", e); } }  }
VelocityTemplateParser { public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException { try (InputStream is = settingsFacade.getRawConfig(templateFilename)) { StringReader reader = new StringReader(IOUtils.toString(is)); SimpleNode node = rs.parse(reader, templateFilename); Template template = new Template(); template.setRuntimeServices(rs); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(new VelocityContext(params), writer); return writer.toString(); } catch (ParseException|IOException e) { throw new VelocityTemplateParsingException("Couldn't merge template into string", e); } }  String mergeTemplateIntoString(String templateFilename, Map<String, Object> params); @Autowired void setSettingsFacade(SettingsFacade settingsFacade); }
VelocityTemplateParser { public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException { try (InputStream is = settingsFacade.getRawConfig(templateFilename)) { StringReader reader = new StringReader(IOUtils.toString(is)); SimpleNode node = rs.parse(reader, templateFilename); Template template = new Template(); template.setRuntimeServices(rs); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(new VelocityContext(params), writer); return writer.toString(); } catch (ParseException|IOException e) { throw new VelocityTemplateParsingException("Couldn't merge template into string", e); } }  String mergeTemplateIntoString(String templateFilename, Map<String, Object> params); @Autowired void setSettingsFacade(SettingsFacade settingsFacade);  }