@Test
  public void calculate() throws Exception {
    RenderRequest request = mock(RenderRequest.class);
    Environment environment = mock(Environment.class, RETURNS_DEEP_STUBS);
    RenderContext renderContext = mock(RenderContext.class);
    Position position = mock(Position.class);
    String propertyName = "propertyName";
    List<Object> arguments = asList(new Object());
    Object value = new Object();
    Optional<Value> optional = Optional.<Value>absent();

    when(request.getEnvironment()).thenReturn(environment);
    when(request.getRenderContext()).thenReturn(renderContext);
    when(environment
            .getPropertyResolver()
            .resolve(
                argThat(
                    theSame(
                        new PropertyResolveRequest(
                            renderContext,
                            environment,
                            position,
                            new Value(value),
                            propertyName,
                            arguments)))))
        .thenReturn(optional);

    Optional<Value> result = underTest.calculate(request, position, propertyName, arguments, value);

    assertSame(optional, result);
  }
  @Test
  public void render() throws Exception {
    RenderRequest request = mock(RenderRequest.class, RETURNS_DEEP_STUBS);
    CompositeNode compositeNode = mock(CompositeNode.class);
    Renderable renderable1 = mock(Renderable.class);
    Renderable renderable2 = mock(Renderable.class);
    Node node1 = mock(Node.class);
    Node node2 = mock(Node.class);

    when(compositeNode.getNodes()).thenReturn(asList(node1, node2));
    when(request
            .getEnvironment()
            .getRenderEnvironment()
            .getRenderNodeService()
            .render(request, node1))
        .thenReturn(renderable1);
    when(request
            .getEnvironment()
            .getRenderEnvironment()
            .getRenderNodeService()
            .render(request, node2))
        .thenReturn(renderable2);

    Renderable result = underTest.render(request, compositeNode);

    Renderable expected = new CompositeRenderable(asList(renderable1, renderable2));
    assertThat(result, (Matcher<? super Renderable>) is(theSame(expected)));
  }
示例#3
0
  @Override
  public Renderable render(RenderRequest request, SetNode node) {
    CalculateExpressionService calculateExpressionService =
        request.getEnvironment().getRenderEnvironment().getCalculateExpressionService();

    Object result = calculateExpressionService.calculate(request, node.getExpression());

    ValueContext valueContext = request.getRenderContext().getValueContext().getCurrent();
    valueContext.with(node.getVariableExpression().getIdentifier(), result);
    return EmptyRenderable.instance();
  }
示例#4
0
 @Override
 public Renderable render(RenderRequest renderRequest, VerbatimNode node) {
   return new StringRenderable(
       node.getContent(), renderRequest.getRenderContext().getEscapeEngineContext().getCurrent());
 }