private Tweet getTweetObjectFromStatus(Status status) { Tweet tweet = new Tweet(); tweet.setId(Long.toString(status.getId())); tweet.setText(status.getText()); tweet.setCreatedAt(status.getCreatedAt()); tweet.setFavCount(status.getFavoriteCount()); User user = status.getUser(); tweet.setUserId(user.getId()); tweet.setUserName(user.getName()); tweet.setUserScreenName(user.getScreenName()); HashtagEntity[] hashtagEntities = status.getHashtagEntities(); List<String> hashtags = new ArrayList<String>(); for (HashtagEntity hashtagEntity : hashtagEntities) { hashtags.add(hashtagEntity.getText()); } tweet.setHashTags(hashtags.toArray(new String[hashtags.size()])); GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { double[] coordinates = {geoLocation.getLongitude(), geoLocation.getLatitude()}; tweet.setCoordinates(coordinates); } return tweet; }
public void testUserAsJSON() throws Exception { // single User HttpClientWrapper http = new HttpClientWrapper(); JSONObject json = getJSONObjectFromClassPath("/dao/user.json"); User user = new UserJSONImpl(json); Assert.assertTrue(user.isGeoEnabled()); Assert.assertFalse(user.isVerified()); Assert.assertEquals(id1.screenName, user.getName()); Assert.assertEquals(id1.screenName, user.getScreenName()); Assert.assertNotNull(user.getLocation()); Assert.assertNotNull(user.getDescription()); Assert.assertNotNull(user.getProfileImageURL()); Assert.assertNotNull(user.getURL()); Assert.assertFalse(user.isProtected()); Assert.assertTrue(0 <= user.getFavouritesCount()); Assert.assertTrue(0 <= user.getFollowersCount()); Assert.assertTrue(0 <= user.getFriendsCount()); Assert.assertNotNull(user.getCreatedAt()); Assert.assertNotNull(user.getTimeZone()); Assert.assertNotNull(user.getProfileBackgroundImageURL()); Assert.assertTrue(0 <= user.getStatusesCount()); Assert.assertNotNull(user.getProfileBackgroundColor()); Assert.assertNotNull(user.getProfileTextColor()); Assert.assertNotNull(user.getProfileLinkColor()); Assert.assertNotNull(user.getProfileSidebarBorderColor()); Assert.assertNotNull(user.getProfileSidebarFillColor()); Assert.assertNotNull(user.getProfileTextColor()); Assert.assertTrue(1 < user.getFollowersCount()); Assert.assertNotNull(user.getStatus().getCreatedAt()); Assert.assertNotNull(user.getStatus().getText()); Assert.assertNotNull(user.getStatus().getSource()); Assert.assertFalse(user.getStatus().isFavorited()); Assert.assertEquals(-1, user.getStatus().getInReplyToStatusId()); Assert.assertEquals(-1, user.getStatus().getInReplyToUserId()); Assert.assertFalse(user.getStatus().isFavorited()); Assert.assertNull(user.getStatus().getInReplyToScreenName()); assertDeserializedFormIsEqual(user); Assert.assertTrue(0 <= user.getListedCount()); List<User> users; // User list users = UserJSONImpl.createUserList( http.get("http://twitter4j.org/en/testcases/statuses/followers/T4J_hudson.json"), conf); Assert.assertTrue(users.size() > 0); assertDeserializedFormIsEqual(users); }