TemplateBasedApplier implements ChangeScriptApplier { public void apply(List<ChangeScript> changeScripts) { String filename = syntax + "_" + getTemplateQualifier() + ".ftl"; try { Map<String, Object> model = new HashMap<String, Object>(); model.put("scripts", changeScripts); model.put("changeLogTableName", changeLogTableName); model.put("delimiter", delimiter); model.put("separator", delimiterType == DelimiterType.row ? "\n" : ""); try { Template template = configuration.getTemplate(filename); template.process(model, writer); } finally { writer.close(); } } catch (FileNotFoundException ex) { throw new UsageException("Could not find template named " + filename + "\n" + "Check that you have got the name of the database syntax correct.", ex); } catch (Exception e) { throw new RuntimeException(e); } } TemplateBasedApplier(Writer writer, String syntax, String changeLogTableName, String delimiter, DelimiterType delimiterType, File templateDirectory); void apply(List<ChangeScript> changeScripts);  }
@Test public void shouldThrowUsageExceptionWhenTemplateNotFound() throws Exception { TemplateBasedApplier applier = new TemplateBasedApplier(new NullWriter(), "some_complete_rubbish", null, ";", DelimiterType.normal, null); try { applier.apply(null); Assert.fail("expected exception"); } catch (UsageException e) { assertThat(e.getMessage(), is("Could not find template named some_complete_rubbish_apply.ftl\n" + "Check that you have got the name of the database syntax correct.")); } }