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