示例#1
0
  @Test
  public void basic() throws IOException {
    final Object[] tst = new Object[] {"test1", "test2"};

    context.checking(
        new Expectations() {
          {
            oneOf(node).getProperty("test");
            will(returnValue(tst));
            oneOf(model).pushNode("test", -1);
            will(returnValue(node));
            oneOf(model).pushNode("0", 0);
            will(returnValue(node));
            oneOf(template).render(model);
            oneOf(model).popNode();
            oneOf(model).pushNode("1", 1);
            will(returnValue(node));
            oneOf(template).render(model);
            oneOf(model).popNode();
            oneOf(model).popNode();
          }
        });

    element = new ArrayElement(property.getName(), template);
    element.render(model);
    context.assertIsSatisfied();
  }
示例#2
0
  @Test
  public void nullArrayNoShow() throws IOException {
    context.checking(
        new Expectations() {
          {
            oneOf(node).getProperty("test");
            will(returnValue(null));
          }
        });

    element = new ArrayElement(property.getName(), template);
    element.render(model);
    context.assertIsSatisfied();
  }
示例#3
0
  @Test(expected = ClassCastException.class)
  public void invalidArray() throws IOException {
    final String tst = "not an array";

    context.checking(
        new Expectations() {
          {
            oneOf(node).getProperty("test");
            will(returnValue(tst));
          }
        });

    element = new ArrayElement(property.getName(), template);
    element.render(model);
    context.assertIsSatisfied();
  }
示例#4
0
  @Test
  public void nullArray() throws IOException {
    context.checking(
        new Expectations() {
          {
            oneOf(node).getProperty("test");
            will(returnValue(null));
            oneOf(model).pushNode("test", -1);
            will(returnValue(node));
            oneOf(model).pushNode("0", 0);
            will(returnValue(node));
            oneOf(template).render(model);
            oneOf(model).popNode();
            oneOf(model).popNode();
          }
        });

    element = new ArrayElement(property.getName(), template);
    element.setShowIfNull(true);
    element.render(model);
    context.assertIsSatisfied();
  }