@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 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 testCamelCaseToLowercase() { assertEquals( "hello_world", GraphObject.Factory.convertCamelCaseToLowercaseWithUnderscores("HelloWorld")); assertEquals( "hello_world", GraphObject.Factory.convertCamelCaseToLowercaseWithUnderscores("helloWorld")); }
@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 testCreateEmptyGraphObject() { GraphObject graphObject = GraphObject.Factory.create(); assertTrue(graphObject != null); }
@SmallTest @MediumTest @LargeTest public void testMapGetReturnsNullForMissingProperty() throws JSONException { GraphUser graphUser = GraphObject.Factory.create(GraphUser.class); assertNull(graphUser.getBirthday()); }
@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 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 testCanTreatAsGraphPlace() { GraphPlace graphPlace = GraphObject.Factory.create(GraphPlace.class); graphPlace.setName("hello"); assertEquals("hello", graphPlace.getName()); }
@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 testCastingCollectionToSameTypeGivesSameObject() { GraphObjectList<Base> base = GraphObject.Factory.createList(Base.class); GraphObjectList<Base> cast = base.castToListOf(Base.class); assertTrue(base == cast); }
@SmallTest @MediumTest @LargeTest public void testCantWrapBadPropertyNameOverrides() { try { GraphObject.Factory.create(BadPropertyOverrideInterfaceGraphObject.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 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 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 testCastingToSameTypeGivesSameObject() { Base base = GraphObject.Factory.create(Base.class); Base cast = base.cast(Base.class); assertTrue(base == cast); }
@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 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 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 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 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 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 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 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 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); }