@SmallTest @MediumTest @LargeTest public void testObjectWrapsIterable() throws JSONException { GraphUser user = GraphObject.Factory.create(GraphUser.class); user.setFirstName("Foo"); user.setLastName("Bar"); List<GraphUser> users = new ArrayList<GraphUser>(); users.add(user); OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class); action.setTags(users); String json = action.getInnerJSONObject().toString(); assertTrue("JSON string should contain last_name", json.contains("last_name")); Object tags = action.getInnerJSONObject().get("tags"); assertNotNull("tags should not be null", tags); assertTrue("tags should be JSONArray", tags instanceof JSONArray); List<GraphObject> retrievedUsers = action.getTags(); assertEquals("Size should be 1", 1, retrievedUsers.size()); GraphUser retrievedUser = retrievedUsers.get(0).cast(GraphUser.class); assertEquals("First name should be Foo", "Foo", retrievedUser.getFirstName()); assertEquals("Last name should be Bar", "Bar", retrievedUser.getLastName()); }
@SmallTest @MediumTest @LargeTest public void testSettingGraphObjectProxyStoresJSONObject() throws JSONException { GraphPlace graphPlace = GraphObject.Factory.create(GraphPlace.class); GraphLocation graphLocation = GraphObject.Factory.create(GraphLocation.class); graphPlace.setLocation(graphLocation); assertEquals( graphLocation.getInnerJSONObject(), graphPlace.getInnerJSONObject().get("location")); }
@SmallTest @MediumTest @LargeTest public void testCanSetComplexTypes() { GraphLocation graphLocation = GraphObject.Factory.create(GraphLocation.class); graphLocation.setCity("Seattle"); GraphPlace graphPlace = GraphObject.Factory.create(GraphPlace.class); graphPlace.setLocation(graphLocation); assertEquals(graphLocation, graphPlace.getLocation()); assertEquals("Seattle", graphPlace.getLocation().getCity()); }
@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 testCreateEmptyGraphObject() { GraphObject graphObject = GraphObject.Factory.create(); assertTrue(graphObject != null); }
@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()); }
@SmallTest @MediumTest @LargeTest public void testMapGetReturnsNullForMissingProperty() throws JSONException { GraphUser graphUser = GraphObject.Factory.create(GraphUser.class); assertNull(graphUser.getBirthday()); }
@SmallTest @MediumTest @LargeTest public void testObjectEquals() { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty("aKey", "aValue"); assertTrue(graphObject.equals(graphObject)); GraphPlace graphPlace = graphObject.cast(GraphPlace.class); assertTrue(graphObject.equals(graphPlace)); assertTrue(graphPlace.equals(graphObject)); GraphObject aDifferentGraphObject = GraphObject.Factory.create(); aDifferentGraphObject.setProperty("aKey", "aDifferentValue"); assertFalse(graphObject.equals(aDifferentGraphObject)); }
@SmallTest @MediumTest @LargeTest public void testCanTreatAsMap() { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty("hello", "world"); assertEquals("world", (String) graphObject.asMap().get("hello")); }
@SmallTest @MediumTest @LargeTest public void testCanTreatAsGraphPlace() { GraphPlace graphPlace = GraphObject.Factory.create(GraphPlace.class); graphPlace.setName("hello"); assertEquals("hello", graphPlace.getName()); }
@SmallTest @MediumTest @LargeTest public void testMapPutOfWrapperPutsJSONObject() throws JSONException { JSONObject jsonObject = new JSONObject(); GraphObject graphObject = GraphObject.Factory.create(jsonObject); graphObject.setProperty("hello", "world"); graphObject.setProperty("hocus", "pocus"); GraphObject parentObject = GraphObject.Factory.create(); parentObject.setProperty("key", graphObject); JSONObject jsonParent = parentObject.getInnerJSONObject(); Object obj = jsonParent.opt("key"); assertNotNull(obj); assertEquals(jsonObject, obj); }
@SmallTest @MediumTest @LargeTest public void testCantWrapBadPropertyNameOverrides() { try { GraphObject.Factory.create(BadPropertyOverrideInterfaceGraphObject.class); fail("Expected exception"); } catch (FacebookGraphObjectException exception) { } }
@SmallTest @MediumTest @LargeTest public void testCantWrapBadSingleParameterMethodName() { try { GraphObject.Factory.create(BadSingleParameterMethodNameGraphObject.class); fail("Expected exception"); } catch (FacebookGraphObjectException exception) { } }
@SmallTest @MediumTest @LargeTest public void testCantWrapNonInterface() { try { GraphObject.Factory.create(GraphObjectClass.class); fail("Expected exception"); } catch (FacebookGraphObjectException exception) { } }
@SmallTest @MediumTest @LargeTest public void testCantWrapBadSetterReturnType() { try { GraphObject.Factory.create(BadSetterReturnTypeGraphObject.class); fail("Expected exception"); } catch (FacebookGraphObjectException exception) { } }
@SmallTest @MediumTest @LargeTest public void testCastingToSameTypeGivesSameObject() { Base base = GraphObject.Factory.create(Base.class); Base cast = base.cast(Base.class); assertTrue(base == cast); }
@SmallTest @MediumTest @LargeTest public void testMapGet() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); assertEquals("world", graphObject.asMap().get("hello")); assertTrue(graphObject.getProperty("fred") == null); }
@SmallTest @MediumTest @LargeTest public void testMapContainsValue() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); assertTrue(graphObject.asMap().containsValue("world")); assertFalse(graphObject.asMap().containsValue("pocus")); }
@SmallTest @MediumTest @LargeTest public void testCastingToBaseTypeGivesSameObject() { Derived derived = GraphObject.Factory.create(Derived.class); Base cast = derived.cast(Base.class); assertTrue(derived == cast); cast = cast.cast(Derived.class); assertTrue(derived == cast); }
@SmallTest @MediumTest @LargeTest public void testGetInnerJSONObject() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); assertEquals(jsonObject, graphObject.getInnerJSONObject()); }
@SmallTest @MediumTest @LargeTest public void testCanConvertNumbers() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("double_as_string", 3.14159); jsonObject.put("int_as_string", 42); GraphMetric metric = GraphObject.Factory.create(jsonObject, GraphMetric.class); assertEquals("42", metric.getIntAsString()); assertNotNull(metric.getDoubleAsString()); assertTrue(metric.getDoubleAsString().startsWith("3.14159")); }
@SmallTest @MediumTest @LargeTest public void testSetProperty() throws JSONException { JSONObject jsonObject = new JSONObject(); GraphObject graphObject = GraphObject.Factory.create(jsonObject); graphObject.setProperty("hello", "world"); graphObject.setProperty("don't imagine", "purple elephants"); assertEquals("world", jsonObject.getString("hello")); assertEquals("purple elephants", jsonObject.getString("don't imagine")); }
@SmallTest @MediumTest @LargeTest public void testMapRemove() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); graphObject.removeProperty("hello"); assertEquals(1, jsonObject.length()); }
@SmallTest @MediumTest @LargeTest public void testMapEntrySet() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); Set<Entry<String, Object>> entrySet = graphObject.asMap().entrySet(); assertEquals(2, entrySet.size()); }
@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); } }
@SmallTest @MediumTest @LargeTest public void testMapValues() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); Collection<Object> values = graphObject.asMap().values(); assertEquals(2, values.size()); assertTrue(values.contains("world")); }
@SmallTest @MediumTest @LargeTest public void testMapPutAll() throws JSONException { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("hello", "world"); map.put("hocus", "pocus"); JSONObject jsonObject = new JSONObject(); GraphObject graphObject = GraphObject.Factory.create(jsonObject); graphObject.asMap().putAll(map); assertEquals("pocus", jsonObject.get("hocus")); assertEquals(2, jsonObject.length()); }
@SmallTest @MediumTest @LargeTest public void testMapClear() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); assertEquals(1, jsonObject.length()); graphObject.asMap().clear(); assertEquals(0, jsonObject.length()); }
@SmallTest @MediumTest @LargeTest public void testCanTreatAsGraphUser() { GraphUser graphUser = GraphObject.Factory.create(GraphUser.class); graphUser.setFirstName("Michael"); assertEquals("Michael", graphUser.getFirstName()); assertEquals("Michael", graphUser.getProperty("first_name")); assertEquals("Michael", graphUser.asMap().get("first_name")); graphUser.setProperty("last_name", "Scott"); assertEquals("Scott", graphUser.getProperty("last_name")); assertEquals("Scott", graphUser.getLastName()); assertEquals("Scott", graphUser.asMap().get("last_name")); }
@SmallTest @MediumTest @LargeTest public void testMapKeySet() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); GraphObject graphObject = GraphObject.Factory.create(jsonObject); Set<String> keySet = graphObject.asMap().keySet(); assertEquals(2, keySet.size()); assertTrue(keySet.contains("hello")); assertTrue(keySet.contains("hocus")); assertFalse(keySet.contains("world")); }