MoshasEngine { public Template describe(String templateName, ViewLogicDescriber describer) { if (describer == null) { throw new IllegalArgumentException("describer is required"); } Template template = manager.loadTemplate(templateName); describeSnippet(template, describer); Element root = template.getRootElement(); root.children().forEach(Element::selected); manager.cacheTemplate(templateName, template); describerCache.put(templateName, describer); return template; } MoshasEngine(TemplateManager manager);  MoshasEngine(); TemplateManager getTemplateManager(); Template describe(String templateName, ViewLogicDescriber describer); Snippet describe(String templateName, String selector, ViewLogicDescriber describer); String process(String templateName, IContext context); void process(String templateName, IContext context, Writer writer);  }
@Test(expected = TemplateNotFoundException.class) public void test() { engine.describe("notfound", t -> {}); }
@Test public void test1() { Template template = engine.describe("META-INF/templates/index.html", t -> {}); Context context = new Context(); StringWriter writer = new StringWriter(); template.render(context, writer); System.out.println(writer.toString()); }
@Test public void variableNotFound() { Template template = engine.describe("META-INF/templates/index.html", t -> t.select("#message", text("message", "japanese"))); Context context = new Context(); StringWriter writer = new StringWriter(); template.render(context, writer); }
@Test public void conversionError() { Template template = engine.describe("META-INF/templates/index.html", t -> t.select("#message", (el, ctx) -> el.text(String.format(Locale.US, "%.2f", ctx.getDouble("message"))))); Context context = new Context(); context.setVariable("message", 3.14); StringWriter writer = new StringWriter(); template.render(context, writer); }