@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);
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCastingCollectionToBaseTypeGivesSameObject() {
    GraphObjectList<Derived> derived = GraphObject.Factory.createList(Derived.class);

    GraphObjectList<Base> cast = derived.castToListOf(Base.class);

    assertTrue((GraphObjectList<?>) derived == (GraphObjectList<?>) cast);
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCastingCollectionToSameTypeGivesSameObject() {
    GraphObjectList<Base> base = GraphObject.Factory.createList(Base.class);

    GraphObjectList<Base> cast = base.castToListOf(Base.class);

    assertTrue(base == cast);
  }
 @SmallTest
 @MediumTest
 @LargeTest
 public void testCollectionRetainAllThrows() throws JSONException {
   try {
     Collection<Integer> collection = GraphObject.Factory.createList(Integer.class);
     collection.retainAll(Arrays.asList());
     fail("Expected exception");
   } catch (UnsupportedOperationException exception) {
   }
 }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionContains() throws JSONException {
    JSONArray array = new JSONArray();
    array.put(5);

    Collection<Integer> collection = GraphObject.Factory.createList(array, Integer.class);
    assertTrue(collection.contains(5));
    assertFalse(collection.contains(6));
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCanGetInnerJSONArray() throws JSONException {
    JSONArray jsonArray = new JSONArray();

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

    assertEquals(jsonArray, collection.getInnerJSONArray());
  }
 @SmallTest
 @MediumTest
 @LargeTest
 public void testCannotCastCollectionOfNonGraphObjects() throws JSONException {
   try {
     GraphObjectList<Integer> collection = GraphObject.Factory.createList(Integer.class);
     collection.castToListOf(GraphLocation.class);
     fail("Expected exception");
   } catch (FacebookGraphObjectException exception) {
   }
 }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionSize() throws JSONException {
    JSONArray array = new JSONArray();

    Collection<Integer> collection = GraphObject.Factory.createList(array, Integer.class);
    assertEquals(0, collection.size());

    array.put(5);
    assertEquals(1, collection.size());
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionAdd() throws JSONException {
    JSONArray array = new JSONArray();

    Collection<Integer> collection = GraphObject.Factory.createList(array, Integer.class);
    collection.add(5);

    assertTrue(array.length() == 1);
    assertTrue(array.optInt(0) == 5);
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCanGetRandomAccess() throws JSONException {
    JSONArray jsonArray = new JSONArray();
    jsonArray.put("Seattle");
    jsonArray.put("Menlo Park");

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

    assertEquals("Menlo Park", collection.get(1));
  }
  @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());
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionIterator() throws JSONException {
    JSONArray array = new JSONArray();
    array.put(5);
    array.put(-1);

    Collection<Integer> collection = GraphObject.Factory.createList(array, Integer.class);
    Iterator<Integer> iter = collection.iterator();
    assertTrue(iter.hasNext());
    assertTrue(iter.next() == 5);
    assertTrue(iter.hasNext());
    assertTrue(iter.next() == -1);
    assertFalse(iter.hasNext());

    for (Integer i : collection) {
      assertNotSame(0, i);
    }
  }
  @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);
  }
  @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());
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionIteratorOfGraphObject() throws JSONException {
    Collection<GraphLocation> collection = GraphObject.Factory.createList(GraphLocation.class);

    GraphLocation seattle = GraphObject.Factory.create(GraphLocation.class);
    seattle.setCity("Seattle");
    collection.add(seattle);
    GraphLocation paris = GraphObject.Factory.create(GraphLocation.class);
    paris.setCity("Paris");
    collection.add(paris);

    Iterator<GraphLocation> iter = collection.iterator();
    assertTrue(iter.hasNext());
    assertEquals(seattle, iter.next());
    assertTrue(iter.hasNext());
    assertEquals(paris, iter.next());
    assertFalse(iter.hasNext());

    for (GraphLocation location : collection) {
      assertTrue(location != null);
    }
  }