예제 #1
0
  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 testRetweetStatusAsJSON() throws Exception {
   // single Status
   HttpClientImpl http = new HttpClientImpl();
   Status status =
       new StatusJSONImpl(
           http.get("http://twitter4j.org/en/testcases/statuses/retweet/6010814202.json"), conf);
   Assert.assertEquals(new Date(1259078050000l), status.getCreatedAt());
   Assert.assertEquals(6011259778l, status.getId());
   Assert.assertEquals(null, status.getInReplyToScreenName());
   Assert.assertEquals(-1l, status.getInReplyToStatusId());
   Assert.assertEquals(-1, status.getInReplyToUserId());
   Assert.assertNull(status.getGeoLocation());
   Assert.assertEquals(
       "<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>", status.getSource());
   Assert.assertEquals(
       "RT @yusukey: この前取材受けた奴 -> 次世代のシステム環境を見据えたアプリケーションサーバー製品の選択 ITpro: http://special.nikkeibp.co.jp/ts/article/0iaa/104388/",
       status.getText());
   Assert.assertEquals(6358482, status.getUser().getId());
   Assert.assertTrue(status.isRetweet());
   assertDeserializedFormIsEqual(status);
 }
 public void testStatusAsJSON() throws Exception {
   // single Status
   HttpClientImpl http = new HttpClientImpl();
   List<Status> statuses =
       StatusJSONImpl.createStatusList(
           http.get("http://twitter4j.org/en/testcases/statuses/public_timeline.json"), conf);
   Status status = statuses.get(0);
   Assert.assertEquals(new Date(1259041785000l), status.getCreatedAt());
   Assert.assertEquals(6000554383l, status.getId());
   Assert.assertEquals("G_Shock22", status.getInReplyToScreenName());
   Assert.assertEquals(6000444309l, status.getInReplyToStatusId());
   Assert.assertEquals(20159829, status.getInReplyToUserId());
   Assert.assertNull(status.getGeoLocation());
   Assert.assertEquals("web", status.getSource());
   Assert.assertEquals(
       "@G_Shock22 I smelled a roast session coming when yu said that shyt about @2koolNicia lol....",
       status.getText());
   Assert.assertEquals(23459577, status.getUser().getId());
   Assert.assertFalse(status.isRetweet());
   assertDeserializedFormIsEqual(statuses);
 }