    @Test
    public void testInvoke() throws Exception {

        Properties p = new Properties();
        p.setProperty("key", "value");
        when(ninjaProperties.getAllCurrentNinjaProperties()).thenReturn(p);

        TemplateEngineRythm rythm = new TemplateEngineRythm(messages, lang,
                ninjaLogger, exceptionHandler, rythmHelper,
                templateEngineManager, ninjaProperties, engine);

        when(contextRenerable.finalizeHeaders(Mockito.eq(result))).thenReturn(
                responseStreams);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        when(responseStreams.getOutputStream()).thenReturn(
                byteArrayOutputStream);

        when(responseStreams.getWriter()).thenReturn(
                new PrintWriter(byteArrayOutputStream));

        when(cookie.isEmpty()).thenReturn(true);
        when(contextRenerable.getSessionCookie()).thenReturn(cookie);

        when(flashCookie.getCurrentFlashCookieData()).thenReturn(
                new HashMap<String, String>());
        when(contextRenerable.getFlashCookie()).thenReturn(flashCookie);
        when(contextRenerable.getRoute()).thenReturn(route);

        when(
                rythmHelper.getRythmTemplateForResult(
                        Mockito.eq(route), Mockito.eq(result),
                        Mockito.eq(".html"))).thenReturn("TemplateName");

        Optional<String> language = Optional.absent();
        when(
                lang.getLanguage(Mockito.eq(contextRenerable),
                        Mockito.eq(Optional.of(result)))).thenReturn(language);

        when(engine.getTemplate(Mockito.eq("TemplateName"), anyObject()))
                .thenReturn(template);

        when(
                template.__setRenderArgs(Mockito
                        .eq(new HashMap<String, Object>()))).thenReturn(
                template);
        when(template.render()).thenReturn("Hellow world from Rythm");

        rythm.invoke(contextRenerable, result);

        assertEquals("Hellow world from Rythm" + SystemUtils.LINE_SEPARATOR,
                byteArrayOutputStream.toString());
    }