예제 #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 testRetrieveJsonElementFromJsonArray2() {
    JsonArray arrayElement = new JsonArray().addString("foo");

    /* Insert an Object */
    JsonArray tester = new JsonArray().addElement(arrayElement);

    JsonElement testElement = (JsonElement) tester.get(0);

    assertEquals(arrayElement.get(0), testElement.asArray().get(0));
  }
예제 #4
0
  @Test
  public void testRetrieveJsonElementFromJsonArray() {
    JsonObject objElement = new JsonObject().putString("foo", "bar");

    /* Insert an Object */
    JsonArray tester = new JsonArray().addElement(objElement);

    JsonElement testElement = (JsonElement) tester.get(0);

    assertEquals(objElement.getString("foo"), testElement.asObject().getString("foo"));
  }
예제 #5
0
  @Test
  public void testJsonElementConversionWithoutException() {
    JsonElement objElement = new JsonObject().putString("foo", "bar");
    JsonElement arrayElement = new JsonArray().addString("foo");

    JsonObject retrievedObject = objElement.asObject();
    JsonArray retrievedArray = arrayElement.asArray();

    log.debug(retrievedObject.encode());
    log.debug(retrievedArray.encode());
  }
예제 #6
0
  @Test
  public void testJsonElementConversionWithException2() {
    JsonElement arrayElement = new JsonArray().addString("foo");

    try {
      arrayElement.asObject();
    } catch (ClassCastException e) {
      return;
    }

    fail("Coercing JsonElement(Array) into JsonObject did not throw a ClassCastException");
  }
예제 #7
0
  @Test
  public void testJsonElementConversionWithException() {
    JsonElement objElement = new JsonObject().putString("foo", "bar");

    try {
      objElement.asArray();
    } catch (ClassCastException e) {
      return;
    }

    fail("Coercing JsonElement(Object) into JsonArray did not throw a ClassCastException");
  }
예제 #8
0
  @Test
  public void testJsonElementTypeCheck() {
    JsonElement objElement = new JsonObject().putString("foo", "bar");
    JsonElement arrayElement = new JsonArray().addString("foo");

    assertTrue(objElement.isObject());
    assertFalse(objElement.isArray());

    assertFalse(arrayElement.isObject());
    assertTrue(arrayElement.isArray());
  }