use of siena.Json in project siena by mandubian.
the class JsonTest method testFind.
public void testFind() {
Json data = map().put("foo", list(1, 2, list(1, 2, map().put("bar", 1))));
Json result = data.find("foo", 2, 2, "bar");
assertNotNull(result);
assertEquals(1, result.asInt());
// try to call at() in a map
result = data.find(1);
assertNull(result);
// try to call get() in a list
result = data.find("foo", "bar");
assertNull(result);
// key not found in map
result = data.find("bar", "baz");
assertNull(result);
// out of bounds
result = data.find("foo", 3);
assertNull(result);
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testArray.
public void testArray() {
Json list = new Json(new Object[] { 1, 2, 3 });
assertEquals(3, list.size());
assertEquals(1, list.at(0).asInt());
assertEquals(2, list.at(1).asInt());
assertEquals(3, list.at(2).asInt());
assertEquals("[1, 2, 3]", list.toString());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testEscapeCharacters.
public void testEscapeCharacters() {
Json json = Json.loads("[\"\\b\\f\\n\\r\\t\\\"\\/\\u0041\"]");
assertTrue(json.isList());
assertEquals(1, json.size());
assertTrue(json.at(0).isString());
assertEquals("[\"\\b\\f\\n\\r\\t\\\"\\/A\"]", json.toString());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testBuildString.
public void testBuildString() {
Json json = new Json("foobar");
assertTrue(json.isString());
assertFalse(json.isBoolean());
assertFalse(json.isList());
assertFalse(json.isMap());
assertFalse(json.isEmpty());
assertEquals(1, json.size());
assertEquals("\"foobar\"", json.toString());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testEnumerations.
public void testEnumerations() {
Json data = list(Gender.MALE);
assertEquals("[\"MALE\"]", data.toString());
assertEquals(Gender.MALE.name(), data.at(0).str());
}
Aggregations