Пример #1
0
  @Test
  public void testRetrieveJsonElementFromJsonObject2() {
    JsonArray arrayElement = new JsonArray().addString("foo");

    JsonObject tester = new JsonObject().putElement("elementField", arrayElement);

    JsonElement testElement = tester.getElement("elementField");

    assertEquals(arrayElement.get(0), testElement.asArray().get(0));
  }
Пример #2
0
  @Test
  public void testRetrieveJsonElementFromJsonObject() {
    JsonObject objElement = new JsonObject().putString("foo", "bar");

    JsonObject tester = new JsonObject().putElement("elementField", objElement);

    JsonElement testElement = tester.getElement("elementField");

    assertEquals(objElement.getString("foo"), testElement.asObject().getString("foo"));
  }
Пример #3
0
  @Test
  public void testRetrieveJsonElementFromJsonObjectWithException() {
    JsonObject tester = new JsonObject().putString("elementField", "foo");

    try {
      tester.getElement("elementField");
    } catch (ClassCastException e) {
      return;
    }

    fail("Retrieving a field that is not a JsonElement did not throw ClassCastException");
  }