HttpClient { public static HttpGet initializeHttpGet(@NonNull final String url) { return initializeHttpGet(url, null); }  static AndroidHttpClient getHttpClient(); static HttpGet initializeHttpGet(@NonNull final String url); static HttpGet initializeHttpGet(@NonNull String url, @Nullable final Context context); static String urlEncode(@NonNull final String url); synchronized static String getWebViewUserAgent(String defaultUserAgent); synchronized static String getWebViewUserAgent(); synchronized static void setWebViewUserAgent(final String userAgent);  }
@Test public void initializeHttpGet_shouldReturnHttpGetWithWebViewUserAgent() throws Exception { HttpGet httpGet = initializeHttpGet(url, context); assertThat(httpGet.getURI().toURL().toString()).isEqualTo(url); assertThat(httpGet.getFirstHeader(ResponseHeader.USER_AGENT.getKey()).getValue()).isEqualTo(userAgent); }
@Test public void initializeHttpGet_withNullContext_shouldNotSetUserAgent() throws Exception { HttpGet httpGet = initializeHttpGet("http: assertThat(httpGet.getFirstHeader(ResponseHeader.USER_AGENT.getKey())).isNull(); }
@Test public void initializeHttpGet_shouldProperlyEncodeUrl() throws Exception { HttpGet httpGet = initializeHttpGet("http: assertThat(httpGet.getURI().toString()) .isEqualTo("http: }
@Test(expected = IllegalArgumentException.class) public void initializeHttpGet_withImproperlyEncodedUrl_shouldThrowIllegalArgumentException() throws Exception { initializeHttpGet("http: }
@Test(expected = IllegalArgumentException.class) public void initializeHttpGet_withMalformedUrl_shouldThrowIllegalArgumentException() throws Exception { initializeHttpGet("bad: }
@Test(expected = NullPointerException.class) public void initializeHttpGet_withNullUrl_shouldThrowNullPointerException() throws Exception { initializeHttpGet(null, context); }
@Test public void initializeHttpGet_withNullContext_shouldNotPopulateUserAgentHeader() throws Exception { HttpGet httpGet = initializeHttpGet(url, null); assertThat(httpGet.getURI().toURL().toString()).isEqualTo(url); assertThat(httpGet.getFirstHeader(ResponseHeader.USER_AGENT.getKey())).isNull(); }