Permalink
Browse files

Merge branch 'patch-1' of git://github.com/DHuckaby/twitter4j

Conflicts:
	twitter4j-core/src/test/java/twitter4j/internal/json/UserJSONImplTest.java
  • Loading branch information...
2 parents a7f0e05 + aa6e62f commit a085f5dafa9570f77147506ee0f07e6e1f88dfff @yusuke committed Dec 20, 2012
@@ -267,12 +267,15 @@ public String getOriginalProfileImageURL() {
}
private String toResizedURL(String originalURL, String sizeSuffix) {
- if(null != originalURL){
+ if (null != originalURL) {
int index = originalURL.lastIndexOf("_");
int suffixIndex = originalURL.lastIndexOf(".");
- return originalURL.substring(0,index)
- +sizeSuffix
- +originalURL.substring(suffixIndex);
+ int slashIndex = originalURL.lastIndexOf("/");
+ String url = originalURL.substring(0, index) + sizeSuffix;
+ if (suffixIndex > slashIndex) {
+ url += originalURL.substring(suffixIndex);
+ }
+ return url;
}
return null;
}
@@ -65,53 +65,20 @@ public void testGetDescriptionURLEntities2() throws JSONException, TwitterExcept
assertEquals(null, userWithoutDescription.getDescription());
assertEquals(0, userWithoutDescription.getDescriptionURLEntities().length);
}
-
- public void testGetURLEntity1() throws JSONException, TwitterException {
- // full url entity
- String rawJson = "{\"profile_sidebar_fill_color\":\"DDEEF6\",\"id\":219570539,\"favourites_count\":252,\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/736851794\\/e6f0992a68eda21a2809efbec2f88050.jpeg\",\"screen_name\":\"gjmp10\",\"following\":false,\"location\":\"\\u4eac\\u90fd\\u5e9c\\u4eac\\u90fd\\u5e02\\u6771\\u5c71\\u533a\\u4e09\\u6761\\u901a\\u5357\\u4e8c\\u7b4b\\u76ee\\u767d\\u5ddd\\u7b4b\\u897f\\u5165\\u30eb\\u4e8c\\u4e01\\u76ee\",\"contributors_enabled\":false,\"profile_background_color\":\"FF8F00\",\"time_zone\":\"Osaka\",\"utc_offset\":32400,\"name\":\"\\u9577\\u3044\\u9577\\u3044\\u9577\\u3044\\u9577\\u3044\\u3042\\u3042\\u3042\\u3042\\u3042\\u3042\\u304b\\u3055\\u305f\\u306a\\u306f\\u3046\",\"notifications\":false,\"geo_enabled\":true,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/2964940756\\/51e2ad9e42297e2be926ec4794b95267_normal.jpeg\",\"id_str\":\"219570539\",\"default_profile\":false,\"follow_request_sent\":false,\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/736851794\\/e6f0992a68eda21a2809efbec2f88050.jpeg\",\"protected\":false,\"profile_link_color\":\"0084B4\",\"verified\":false,\"entities\":{\"description\":{\"urls\":[{\"expanded_url\":\"http:\\/\\/jigtwi.jp\\/\",\"display_url\":\"jigtwi.jp\",\"url\":\"http:\\/\\/t.co\\/n578Jr6S\",\"indices\":[31,51]},{\"expanded_url\":\"http:\\/\\/twitpic.com\\/7tx0wk\",\"display_url\":\"twitpic.com\\/7tx0wk\",\"url\":\"http:\\/\\/t.co\\/i2cX7pEY\",\"indices\":[52,72]},{\"expanded_url\":\"http:\\/\\/twitter.com\\/ak_12\\/status\\/12813969077051392\",\"display_url\":\"twitter.com\\/ak_12\\/status\\/1\\u2026\",\"url\":\"http:\\/\\/t.co\\/PlItS8jh\",\"indices\":[77,97]}]},\"url\":{\"urls\":[{\"display_url\":\"google.co.jp\\/search?q=adgjg\",\"expanded_url\":\"https:\\/\\/www.google.co.jp\\/search?q=adgjg\",\"indices\":[0,21],\"url\":\"https:\\/\\/t.co\\/gLcBbz6G\"}]}},\"listed_count\":5,\"profile_use_background_image\":true,\"statuses_count\":979,\"profile_text_color\":\"333333\",\"created_at\":\"Thu Nov 25 06:48:26 +0000 2010\",\"lang\":\"ja\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/2964940756\\/51e2ad9e42297e2be926ec4794b95267_normal.jpeg\",\"is_translator\":false,\"profile_sidebar_border_color\":\"FFFFFF\",\"friends_count\":12,\"url\":\"https:\\/\\/t.co\\/gLcBbz6G\",\"default_profile_image\":false,\"followers_count\":10,\"description\":\"\\n09012345678\\n@kouda12345 #test http:\\/\\/t.co\\/n578Jr6S http:\\/\\/t.co\\/i2cX7pEY http:\\/\\/t.co\\/PlItS8jh 0123456789\\n\\u3066\\u3059\\u3068 @gjmp9\",\"profile_background_tile\":true}";
- JSONObject json = new JSONObject(rawJson);
- UserJSONImpl user = new UserJSONImpl(json);
-
- URLEntity urlEntity = user.getURLEntity();
- assertNotNull(urlEntity);
- assertEquals("https://www.google.co.jp/search?q=adgjg", urlEntity.getExpandedURL());
- assertEquals("google.co.jp/search?q=adgjg", urlEntity.getDisplayURL());
- assertEquals("https://t.co/gLcBbz6G", urlEntity.getURL());
- assertEquals(0, urlEntity.getStart());
- assertEquals(21, urlEntity.getEnd());
- }
-
- public void testGetURLEntity2() throws JSONException, TwitterException {
- // url, indices only
- String rawJson = "{\"profile_sidebar_fill_color\":\"F3F3F3\",\"id\":4311171,\"favourites_count\":118,\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/725168446\\/fed71f230b033a13a69d803d464871ec.gif\",\"screen_name\":\"ApplePedlar\",\"following\":false,\"location\":\"Fukui, Japan\",\"contributors_enabled\":false,\"profile_background_color\":\"FDF4D3\",\"time_zone\":\"Tokyo\",\"utc_offset\":32400,\"name\":\"Naoya Hatayama\",\"notifications\":false,\"geo_enabled\":true,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1197534673\\/100x100_normal.png\",\"id_str\":\"4311171\",\"default_profile\":false,\"follow_request_sent\":false,\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/725168446\\/fed71f230b033a13a69d803d464871ec.gif\",\"protected\":false,\"profile_link_color\":\"990000\",\"verified\":false,\"entities\":{\"description\":{\"urls\":[]},\"url\":{\"urls\":[{\"display_url\":null,\"expanded_url\":null,\"indices\":[0,30],\"url\":\"http:\\/\\/twitter.com\\/ApplePedlar\"}]}},\"listed_count\":74,\"profile_use_background_image\":true,\"statuses_count\":10130,\"profile_text_color\":\"333333\",\"created_at\":\"Thu Apr 12 06:27:44 +0000 2007\",\"lang\":\"ja\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1197534673\\/100x100_normal.png\",\"is_translator\":false,\"profile_sidebar_border_color\":\"FFFFFF\",\"friends_count\":984,\"url\":\"http:\\/\\/twitter.com\\/ApplePedlar\",\"default_profile_image\":false,\"followers_count\":901,\"description\":\"\\u3081\\u304c\\u306d\\u4f1a\\u9928\\u3067\\u50cd\\u304f\\u30e2\\u30d0\\u30a4\\u30eb\\u7cfb\\u958b\\u767a\\u8005\\u3067\\u3059\\n#kosen #fukui #sabae #jigtwi #Twitter4J #DQ10\",\"profile_background_tile\":true}";
- JSONObject json = new JSONObject(rawJson);
- UserJSONImpl user = new UserJSONImpl(json);
-
- URLEntity urlEntity = user.getURLEntity();
- assertNotNull(urlEntity);
- assertEquals("http://twitter.com/ApplePedlar", urlEntity.getExpandedURL());
- assertEquals("http://twitter.com/ApplePedlar", urlEntity.getDisplayURL());
- assertEquals("http://twitter.com/ApplePedlar", urlEntity.getURL());
- assertEquals(0, urlEntity.getStart());
- assertEquals(30, urlEntity.getEnd());
- }
-
- public void testGetURLEntity3() throws JSONException, TwitterException {
- // url is null
- String rawJson = "{\"id\":78941611,\"id_str\":\"78941611\",\"name\":\"Harsha Bhogle\",\"screen_name\":\"bhogleharsha\",\"location\":\"Mumbai, India\",\"description\":\"once upon a time a chem engr and mgmt grad,now cricket and motivational speaking my calling!\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":540458,\"friends_count\":83,\"listed_count\":4229,\"created_at\":\"Thu Oct 01 16:18:03 +0000 2009\",\"favourites_count\":3,\"utc_offset\":19800,\"time_zone\":\"Chennai\",\"geo_enabled\":false,\"verified\":true,\"statuses_count\":12205,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/2769690929\\/61db65334849e8876c538051e885cdab_normal.png\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/2769690929\\/61db65334849e8876c538051e885cdab_normal.png\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null}";
- JSONObject json = new JSONObject(rawJson);
- UserJSONImpl user = new UserJSONImpl(json);
-
- assertNull(user.getURL());
-
- URLEntity urlEntity = user.getURLEntity();
- assertNotNull(urlEntity);
- assertEquals("", urlEntity.getExpandedURL());
- assertEquals("", urlEntity.getDisplayURL());
- assertEquals("", urlEntity.getURL());
- assertEquals(0, urlEntity.getStart());
- assertEquals(0, urlEntity.getEnd());
+
+ public void testProfileImageURL() throws JSONException, TwitterException {
+ String rawJsonWithoutProfileImageExtension = "{\"id\":400609977,\"id_str\":\"400609977\",\"name\":\"Chris Bautista\",\"screen_name\":\"ayecrispy\",\"location\":\"Jacksonville, FL\",\"description\":\"I'm a gamer and will always be one. I like to keep up with the entertainment life. Where it's celebrities, technology or trying to keep up with latest trend\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":17,\"friends_count\":177,\"listed_count\":0,\"created_at\":\"Sat Oct 29 09:23:10 +0000 2011\",\"favourites_count\":0,\"utc_offset\":-18000,\"time_zone\":\"Eastern Time (US & Canada)\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":113,\"lang\":\"en\",\"status\":{\"created_at\":\"Sun Dec 16 02:37:57 +0000 2012\",\"id\":280139673333035008,\"id_str\":\"280139673333035008\",\"text\":\"Gotta love olive Garden!\",\"source\":\"\\u003ca href=\\\"http:\\/\\/tweedleapp.com\\/\\\" rel=\\\"nofollow\\\"\\u003e Tweedle\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false},\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"1A1B1F\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme9\\/bg.gif\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme9\\/bg.gif\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1835646533\\/gu44kEhi_normal\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1835646533\\/gu44kEhi_normal\",\"profile_link_color\":\"2FC2EF\",\"profile_sidebar_border_color\":\"181A1E\",\"profile_sidebar_fill_color\":\"252429\",\"profile_text_color\":\"666666\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false}";
+ JSONObject jsonWithoutProfileImageExtension = new JSONObject(rawJsonWithoutProfileImageExtension);
+ UserJSONImpl userWithoutProfileImageExtension = new UserJSONImpl(jsonWithoutProfileImageExtension);
+
+ assertEquals(userWithoutProfileImageExtension.getBiggerProfileImageURL(), "http://si0.twimg.com/profile_images/1835646533/gu44kEhi_bigger");
+ assertEquals(userWithoutProfileImageExtension.getOriginalProfileImageURL(), "http://si0.twimg.com/profile_images/1835646533/gu44kEhi");
+
+ String rawJsonWithProfileImageExtension = "{\"id\":613742117,\"id_str\":\"613742117\",\"name\":\"Tweedle\",\"screen_name\":\"tweedleapp\",\"location\":\"\",\"description\":\"Twitter application for Android, follow this account for updates.\\r\\n\\r\\nDeveloped by @HandlerExploit\",\"url\":\"http:\\/\\/tweedleapp.com\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\/\\/tweedleapp.com\",\"expanded_url\":null,\"indices\":[0,21]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":2210,\"friends_count\":1,\"listed_count\":20,\"created_at\":\"Wed Jun 20 20:42:48 +0000 2012\",\"favourites_count\":1,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":323,\"lang\":\"en\",\"status\":{\"created_at\":\"Sun Dec 16 06:47:33 +0000 2012\",\"id\":280202487317790721,\"id_str\":\"280202487317790721\",\"text\":\"@bcw_ It is better in some aspects, but in others it is not ideal. We need to add a way to notify the user better though.\",\"source\":\"web\",\"truncated\":false,\"in_reply_to_status_id\":280202314080464896,\"in_reply_to_status_id_str\":\"280202314080464896\",\"in_reply_to_user_id\":101066646,\"in_reply_to_user_id_str\":\"101066646\",\"in_reply_to_screen_name\":\"bcw_\",\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"bcw_\",\"name\":\"Verified Bradley\",\"id\":101066646,\"id_str\":\"101066646\",\"indices\":[0,5]}]},\"favorited\":false,\"retweeted\":false},\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/2433552309\\/dltv4u9hajvoxsne5bly_normal.png\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/2433552309\\/dltv4u9hajvoxsne5bly_normal.png\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":true,\"follow_request_sent\":false,\"notifications\":false}";
+ JSONObject jsonWithProfileImageExtension = new JSONObject(rawJsonWithProfileImageExtension);
+ UserJSONImpl userWithProfileImageExtension = new UserJSONImpl(jsonWithProfileImageExtension);
+
+ assertEquals(userWithProfileImageExtension.getBiggerProfileImageURL(), "http://si0.twimg.com/profile_images/2433552309/dltv4u9hajvoxsne5bly_bigger.png");
+ assertEquals(userWithProfileImageExtension.getOriginalProfileImageURL(), "http://si0.twimg.com/profile_images/2433552309/dltv4u9hajvoxsne5bly.png");
}
-
-
}

0 comments on commit a085f5d

Please sign in to comment.