コード例 #1
0
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCanConvertFromGraphObject() throws JSONException {
    GraphObject graphObject = GraphObject.Factory.create();
    graphObject.setProperty("city", "Paris");
    graphObject.setProperty("country", "France");

    JSONObject jsonPlace = new JSONObject();
    jsonPlace.put("location", graphObject);
    jsonPlace.put("name", "Eiffel Tower");

    GraphPlace graphPlace = GraphObject.Factory.create(jsonPlace, GraphPlace.class);
    GraphLocation graphLocation = graphPlace.getLocation();
    assertEquals("Paris", graphLocation.getCity());
  }
コード例 #2
0
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionWrapsJSONObject() throws JSONException {
    JSONObject jsonLocation = new JSONObject();
    jsonLocation.put("city", "Seattle");

    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonLocation);
    Collection<GraphLocation> locationsGraphObjectCollection =
        GraphObject.Factory.createList(jsonArray, GraphLocation.class);
    assertTrue(locationsGraphObjectCollection != null);

    GraphLocation graphLocation = locationsGraphObjectCollection.iterator().next();
    assertTrue(graphLocation != null);
    assertEquals("Seattle", graphLocation.getCity());
  }
コード例 #3
0
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCanCastCollectionOfGraphObjects() throws JSONException {
    JSONObject jsonSeattle = new JSONObject();
    jsonSeattle.put("city", "Seattle");

    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonSeattle);

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

    GraphObjectList<GraphLocation> locationCollection =
        collection.castToListOf(GraphLocation.class);
    assertTrue(locationCollection != null);

    GraphLocation seattle = locationCollection.iterator().next();
    assertTrue(seattle != null);
    assertEquals("Seattle", seattle.getCity());
  }