public class TestArrayNode
extends BaseMapTest
{
public void testBasics() throws IOException
{
ArrayNode n = new ArrayNode(JsonNodeFactory.instance);
assertStandardEquals(n);
assertFalse(n.elements().hasNext());
assertFalse(n.fieldNames().hasNext());
TextNode text = TextNode.valueOf("x");
n.add(text);
assertEquals(1, n.size());
assertFalse(0 == n.hashCode());
assertTrue(n.elements().hasNext());
// no field names for arrays
assertFalse(n.fieldNames().hasNext());
assertNull(n.get("x")); // not used with arrays
assertTrue(n.path("x").isMissingNode());
assertSame(text, n.get(0));
// single element, so:
assertFalse(n.has("field"));
assertFalse(n.hasNonNull("field"));
assertTrue(n.has(0));
assertTrue(n.hasNonNull(0));
assertFalse(n.has(1));
assertFalse(n.hasNonNull(1));
// add null node too
n.add((JsonNode) null);
assertEquals(2, n.size());
assertTrue(n.get(1).isNull());
assertTrue(n.has(1));
assertFalse(n.hasNonNull(1));
// change to text
n.set(1, text);
assertSame(text, n.get(1));
n.set(0, null);
assertTrue(n.get(0).isNull());
// and finally, clear it all
ArrayNode n2 = new ArrayNode(JsonNodeFactory.instance);
n2.add("foobar");
assertFalse(n.equals(n2));
n.addAll(n2);
assertEquals(3, n.size());
assertFalse(n.get(0).isTextual());