Created
November 16, 2012 02:22
-
-
Save komiya-atsushi/4083361 to your computer and use it in GitHub Desktop.
TFJ-705 testing code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package twitter4j.internal.json; | |
import java.io.IOException; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Properties; | |
import twitter4j.TwitterException; | |
import twitter4j.conf.Configuration; | |
import twitter4j.internal.http.HttpResponse; | |
import twitter4j.internal.org.json.JSONException; | |
import twitter4j.internal.org.json.JSONObject; | |
import junit.framework.TestCase; | |
public class QueryResultJSONImplTest extends TestCase { | |
public QueryResultJSONImplTest(String name) { | |
super(name); | |
} | |
public void testNextResultsReturnsNotNull() throws Exception { | |
final String str = "{\"statuses\":[{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Wed Nov 14 07:17:11 +0000 2012\",\"id\":268613531161731072,\"id_str\":\"268613531161731072\",\"text\":\"@sigpwned And I get java.lang.IllegalArgumentException in ETMLEntityString. could you take a look at my branch? https:\\/\\/t.co\\/e6wHc6rm thx\",\"source\":\"\\u003ca href=\\\"http:\\/\\/sites.google.com\\/site\\/yorufukurou\\/\\\" rel=\\\"nofollow\\\"\\u003eYoruFukurou\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":119637086,\"in_reply_to_user_id_str\":\"119637086\",\"in_reply_to_screen_name\":\"sigpwned\",\"user\":{\"id\":34304382,\"id_str\":\"34304382\",\"name\":\"Yusuke Yamamoto\",\"screen_name\":\"yusukey\",\"location\":\"Tokyo Japan\",\"description\":\"Passionate about open source softwares.\\r\\nAuthor of #twitter4J and #samurai\\r\\n\\u65e5\\u672c\\u8a9e\\u306f @yusuke\",\"url\":\"http:\\/\\/samuraism.jp\\/\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\/\\/samuraism.jp\\/\",\"expanded_url\":null,\"indices\":[0,20]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":1070,\"friends_count\":80,\"listed_count\":67,\"created_at\":\"Wed Apr 22 15:38:27 +0000 2009\",\"favourites_count\":6,\"utc_offset\":32400,\"time_zone\":\"Tokyo\",\"geo_enabled\":true,\"verified\":false,\"statuses_count\":1067,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"8B542B\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme8\\/bg.gif\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme8\\/bg.gif\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1773799229\\/yusuke-square_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1773799229\\/yusuke-square_normal.jpg\",\"profile_banner_url\":\"https:\\/\\/si0.twimg.com\\/profile_banners\\/34304382\\/1348130623\",\"profile_link_color\":\"9D582E\",\"profile_sidebar_border_color\":\"D9B17E\",\"profile_sidebar_fill_color\":\"EADEAA\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"entities\":{\"hashtags\":[],\"urls\":[{\"url\":\"https:\\/\\/t.co\\/e6wHc6rm\",\"expanded_url\":\"https:\\/\\/github.com\\/yusuke\\/twitter4j\\/tree\\/TFJ-671\",\"display_url\":\"github.com\\/yusuke\\/twitter\\u2026\",\"indices\":[112,133]}],\"user_mentions\":[{\"screen_name\":\"sigpwned\",\"name\":\"Andy Boothe\",\"id\":119637086,\"id_str\":\"119637086\",\"indices\":[0,9]}]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false}],\"search_metadata\":{\"completed_in\":0.015,\"max_id\":268613531161731072,\"max_id_str\":\"268613531161731072\",\"next_results\":\"?max_id=268613531161731071&q=yusukey&count=1&include_entities=1&result_type=recent\",\"query\":\"yusukey\",\"refresh_url\":\"?since_id=268613531161731072&q=yusukey&result_type=recent&include_entities=1\",\"count\":1,\"since_id\":0,\"since_id_str\":\"0\"}}"; | |
HttpResponse resp = new MockHttpResponse(str); | |
QueryResultJSONImpl queryResult = new QueryResultJSONImpl(resp, new MockConfiguration()); | |
assertNotNull(queryResult.nextQuery()); | |
} | |
private static class MockHttpResponse extends HttpResponse { | |
private String respStr; | |
public MockHttpResponse(String respStr) { | |
super(null); | |
this.respStr = respStr; | |
} | |
@Override | |
public String getResponseHeader(String name) { | |
return null; | |
} | |
@Override | |
public Map<String, List<String>> getResponseHeaderFields() { | |
return null; | |
} | |
@Override | |
public void disconnect() throws IOException { | |
} | |
@Override | |
public JSONObject asJSONObject() throws TwitterException { | |
try { | |
return new JSONObject(respStr); | |
} catch (JSONException e) { | |
throw new TwitterException(e); | |
} | |
} | |
} | |
private static class MockConfiguration implements Configuration { | |
@Override | |
public boolean isPrettyDebugEnabled() { | |
return false; | |
} | |
@Override | |
public boolean isGZIPEnabled() { | |
return false; | |
} | |
@Override | |
public boolean isDalvik() { | |
return false; | |
} | |
@Override | |
public boolean isGAE() { | |
return false; | |
} | |
@Override | |
public boolean isDebugEnabled() { | |
return false; | |
} | |
@Override | |
public String getUserAgent() { | |
return null; | |
} | |
@Override | |
public String getUser() { | |
return null; | |
} | |
@Override | |
public String getPassword() { | |
return null; | |
} | |
@Override | |
public Map<String, String> getRequestHeaders() { | |
return null; | |
} | |
@Override | |
public String getHttpProxyHost() { | |
return null; | |
} | |
@Override | |
public String getHttpProxyUser() { | |
return null; | |
} | |
@Override | |
public String getHttpProxyPassword() { | |
return null; | |
} | |
@Override | |
public int getHttpProxyPort() { | |
return 0; | |
} | |
@Override | |
public int getHttpConnectionTimeout() { | |
return 0; | |
} | |
@Override | |
public int getHttpReadTimeout() { | |
return 0; | |
} | |
@Override | |
public int getHttpStreamingReadTimeout() { | |
return 0; | |
} | |
@Override | |
public int getHttpRetryCount() { | |
return 0; | |
} | |
@Override | |
public int getHttpRetryIntervalSeconds() { | |
return 0; | |
} | |
@Override | |
public int getHttpMaxTotalConnections() { | |
return 0; | |
} | |
@Override | |
public int getHttpDefaultMaxPerRoute() { | |
return 0; | |
} | |
@Override | |
public String getOAuthConsumerKey() { | |
return null; | |
} | |
@Override | |
public String getOAuthConsumerSecret() { | |
return null; | |
} | |
@Override | |
public String getOAuthAccessToken() { | |
return null; | |
} | |
@Override | |
public String getOAuthAccessTokenSecret() { | |
return null; | |
} | |
@Override | |
public String getClientVersion() { | |
return null; | |
} | |
@Override | |
public String getClientURL() { | |
return null; | |
} | |
@Override | |
public String getRestBaseURL() { | |
return null; | |
} | |
@Override | |
public String getStreamBaseURL() { | |
return null; | |
} | |
@Override | |
public String getOAuthRequestTokenURL() { | |
return null; | |
} | |
@Override | |
public String getOAuthAuthorizationURL() { | |
return null; | |
} | |
@Override | |
public String getOAuthAccessTokenURL() { | |
return null; | |
} | |
@Override | |
public String getOAuthAuthenticationURL() { | |
return null; | |
} | |
@Override | |
public String getUserStreamBaseURL() { | |
return null; | |
} | |
@Override | |
public String getSiteStreamBaseURL() { | |
return null; | |
} | |
@Override | |
public boolean isIncludeMyRetweetEnabled() { | |
return false; | |
} | |
@Override | |
public boolean isJSONStoreEnabled() { | |
return false; | |
} | |
@Override | |
public boolean isMBeanEnabled() { | |
return false; | |
} | |
@Override | |
public boolean isUserStreamRepliesAllEnabled() { | |
return false; | |
} | |
@Override | |
public boolean isStallWarningsEnabled() { | |
return false; | |
} | |
@Override | |
public String getMediaProvider() { | |
return null; | |
} | |
@Override | |
public String getMediaProviderAPIKey() { | |
return null; | |
} | |
@Override | |
public Properties getMediaProviderParameters() { | |
return null; | |
} | |
@Override | |
public int getAsyncNumThreads() { | |
return 0; | |
} | |
@Override | |
public long getContributingTo() { | |
return 0; | |
} | |
@Override | |
public String getDispatcherImpl() { | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment