Exemplo n.º 1
0
  @Test(expected = RenderException.class)
  public void dateModifyWithWrongFormat() throws Exception {
    JtwigModelMap model = new JtwigModelMap();
    model.withModelAttribute("time", LocalDate.parse("2014-01-01").toDate());

    JtwigTemplate.inlineTemplate("{{ date_modify(time, '+1 unknown') }}").render(model);
  }
Exemplo n.º 2
0
  @Test
  public void dateFormat() throws Exception {
    JtwigModelMap model = new JtwigModelMap();
    model.withModelAttribute("time", LocalDate.parse("2014-01-01").toDate());

    String result = JtwigTemplate.inlineTemplate("{{ date(time) }}").render(model);

    assertThat(result, is(equalTo("2014-01-01T00:00:00")));
  }
Exemplo n.º 3
0
  @Test
  public void dateModify() throws Exception {
    JtwigModelMap model = new JtwigModelMap();
    model.withModelAttribute("time", LocalDate.parse("2014-01-01").toDate());

    String result =
        JtwigTemplate.inlineTemplate("{{ date_modify(time, '+1 day') | date('yyyy-MM-dd') }}")
            .render(model);

    assertThat(result, is(equalTo("2014-01-02")));
  }
Exemplo n.º 4
0
  @Test
  public void testExtendsVariableDefinedTemplate() throws Exception {
    JtwigResource oneResource = mock(JtwigResource.class);
    JtwigResource twoResource = mock(JtwigResource.class);

    when(resource.resolve("num-one")).thenReturn(oneResource);
    when(resource.resolve("num-two")).thenReturn(twoResource);

    when(oneResource.retrieve()).thenReturn(new ByteArrayInputStream("first".getBytes()));
    when(twoResource.retrieve()).thenReturn(new ByteArrayInputStream("second".getBytes()));

    when(resource.retrieve()).thenReturn(new ByteArrayInputStream("{% extends var %}".getBytes()));

    context.withModelAttribute("var", "num-two");
    underTest.output(toTheOutputStream(), context);
    assertThat(theOutput(), is("second"));
  }