コード例 #1
0
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCanSetRandomAccess() throws JSONException {
    JSONArray jsonArray = new JSONArray();

    GraphObjectList<String> collection = GraphObject.Factory.createList(jsonArray, String.class);

    collection.add("Seattle");
    collection.add("Menlo Park");

    collection.set(1, "Ann Arbor");
    assertEquals("Ann Arbor", collection.get(1));
  }
コード例 #2
0
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionPutOfWrapperPutsJSONObject() throws JSONException {
    JSONObject jsonObject = new JSONObject();

    GraphObject graphObject = GraphObject.Factory.create(jsonObject);
    graphObject.setProperty("hello", "world");
    graphObject.setProperty("hocus", "pocus");

    GraphObjectList<GraphObject> parentList = GraphObject.Factory.createList(GraphObject.class);
    parentList.add(graphObject);

    JSONArray jsonArray = parentList.getInnerJSONArray();

    Object obj = jsonArray.opt(0);

    assertNotNull(obj);
    assertEquals(jsonObject, obj);

    parentList.set(0, graphObject);

    obj = jsonArray.opt(0);

    assertNotNull(obj);
    assertEquals(jsonObject, obj);
  }
コード例 #3
0
  @SmallTest
  @MediumTest
  @LargeTest
  public void testMapPutOfWrapperPutsJSONArray() throws JSONException {
    JSONArray jsonArray = new JSONArray();

    GraphObjectList<String> graphObjectList =
        GraphObject.Factory.createList(jsonArray, String.class);
    graphObjectList.add("hello");
    graphObjectList.add("world");

    GraphObject parentObject = GraphObject.Factory.create();
    parentObject.setProperty("key", graphObjectList);

    JSONObject jsonParent = parentObject.getInnerJSONObject();
    Object obj = jsonParent.opt("key");

    assertNotNull(obj);
    assertEquals(jsonArray, obj);
  }