TemplateEngineRocker implements TemplateEngine { @Override public void invoke(Context context, Result result) { try { doInvoke(context, result); } catch (CompileDiagnosticException e) { throwRenderingException(context, result, e); } catch (ParserException e) { throwRenderingException(context, result, e); } catch (RenderingException e) { throwRenderingException(context, result, e); } } @Inject  TemplateEngineRocker(Injector injector,
                                Router router,
                                Messages messages,
                                NinjaProperties ninjaProperties,
                                Provider<Lang> langProvider,
                                TemplateEngineHelper templateEngineHelper,
                                NinjaRockerFactory ninjaRockerFactory); final void loadCustomErrorTemplates(); Class<DefaultRockerModel> getCustomErrorViewClass(String className); @Override String getContentType(); @Override String getSuffixOfTemplatingEngine(); @Override void invoke(Context context, Result result); void doInvoke(Context context, Result result); void throwRenderingException(
            Context context,
            Result result,
            CompileDiagnosticException cause); void throwRenderingException(
            Context context,
            Result result,
            ParserException cause); void throwRenderingException(
            Context context,
            Result result,
            RenderingException cause); static RuntimeException renderingOrRuntimeException(String message, Exception cause); static RuntimeException renderingOrRuntimeException(String message,
                                                        Exception cause,
                                                        Result result,
                                                        String title,
                                                        String sourcePath,
                                                        int lineOfError);  }
@Test public void commonErrorTemplate() throws Exception { RockerModel model = com.fizzed.ninja.rocker.views.common_error.template(new Message("Hello!")); when(context.getContextPath()).thenReturn("/context"); when(result.getRenderable()).thenReturn(model); String out = invoke(context, result); assertThat(out, containsString("href=\"/context/\"")); }
@Test public void autoTemplateNaming() throws Exception { when(context.getContextPath()).thenReturn("/context"); when(templateEngineHelper.getTemplateForResult(context.getRoute(), result, ".rocker.html")).thenReturn("views/context_path.rocker.html"); String out = invoke(context, result); assertThat(out, is("/context")); }
@Test public void customApplicationTemplate() throws Exception { when(context.getContextPath()).thenReturn("/context"); when(context.getAttribute("USER", User.class)).thenReturn(new User("Joe")); when(templateEngineHelper.getTemplateForResult(context.getRoute(), result, ".rocker.html")).thenReturn("views/application_template.rocker.html"); String out = invoke(context, result); assertThat(out, is("Joe")); }