@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 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 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 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()); }