@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(); }
@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(); }
@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(); }
@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(); }