use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class JsonObjectTest method testCreateFromMapNestedJsonArray.
@Test
public void testCreateFromMapNestedJsonArray() {
Map<String, Object> map = new HashMap<>();
JsonArray nestedArr = new JsonArray().add("foo");
map.put("nested", nestedArr);
JsonObject obj = new JsonObject(map);
JsonArray nestedRetrieved = obj.getJsonArray("nested");
assertEquals("foo", nestedRetrieved.getString(0));
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class JsonArrayTest method testGetJsonArray.
@Test
public void testGetJsonArray() {
JsonArray arr = new JsonArray().add("foo");
jsonArray.add(arr);
assertEquals(arr, jsonArray.getJsonArray(0));
try {
jsonArray.getJsonArray(-1);
fail();
} catch (IndexOutOfBoundsException e) {
// OK
}
try {
jsonArray.getJsonArray(1);
fail();
} catch (IndexOutOfBoundsException e) {
// OK
}
jsonArray.add(123);
try {
jsonArray.getJsonArray(1);
fail();
} catch (ClassCastException e) {
// OK
}
jsonArray.addNull();
assertNull(jsonArray.getJsonArray(2));
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class JsonArrayTest method testInvalidValsOnCopy.
@Test
public void testInvalidValsOnCopy() {
List<Object> invalid = new ArrayList<>();
invalid.add(new SomeClass());
JsonArray arr = new JsonArray(invalid);
try {
arr.copy();
fail();
} catch (IllegalStateException e) {
// OK
}
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class JsonArrayTest method testContains.
@Test
public void testContains() {
jsonArray.add("wibble");
jsonArray.add(true);
jsonArray.add(123);
JsonObject obj = new JsonObject();
JsonArray arr = new JsonArray();
jsonArray.add(obj);
jsonArray.add(arr);
assertFalse(jsonArray.contains("eek"));
assertFalse(jsonArray.contains(false));
assertFalse(jsonArray.contains(321));
assertFalse(jsonArray.contains(new JsonObject().put("blah", "flib")));
assertFalse(jsonArray.contains(new JsonArray().add("oob")));
assertTrue(jsonArray.contains("wibble"));
assertTrue(jsonArray.contains(true));
assertTrue(jsonArray.contains(123));
assertTrue(jsonArray.contains(obj));
assertTrue(jsonArray.contains(arr));
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class JsonArrayTest method testCreateFromListNestedJsonArray.
@Test
public void testCreateFromListNestedJsonArray() {
List<Object> list = new ArrayList<>();
list.add("foo");
list.add(123);
JsonArray arr2 = new JsonArray().add("blah").add("wibble");
list.add(arr2);
JsonArray arr = new JsonArray(list);
assertEquals("foo", arr.getString(0));
assertEquals(Integer.valueOf(123), arr.getInteger(1));
assertSame(list, arr.getList());
assertSame(arr2, arr.getJsonArray(2));
}
Aggregations