@Test
public void testKey() {

    boolean keyNull = false;
    try {
        key(null, "val");
    } catch (final NullPointerException e) {
        keyNull = true;
    }
    assertTrue("key(null, val) should throw NullPointerException", keyNull);
    assertEquals("key cursor getKey() returns input",
            "foo", key("foo").getKey());
    assertEquals("key(key, val) is retrievable",
            "bar", key("foo", "bar").get().getString("foo"));
    assertEquals("key(key, val).key(key2, val2) is retrievable",
            "bar2", key("foo", "bar").key("foo2", "bar2").get().getString("foo2"));
    assertEquals("key(key).val(val) is retrievable",
            "bar", key("foo").val("bar").get().getString("foo"));
    assertEquals("key(key).val(val).key(key2).val(val2) is retrievable",
            "bar2", key("foo").val("bar").key("foo2").val("bar2").get().getString("foo2"));
    assertTrue("Key.toValue should return a JsonObject.",
            key("foo", "bar").toValue().get() instanceof JsonObject);
    assertEquals("Key.toValue obj should have appropriate key.", "bar",
            ((JsonObject) key("foo", "bar").toValue().get()).getString("foo"));
}