HttpClient { OkHttpClient getUnderlying() { return okClient; } private  HttpClient(OkHttpClient okClient); HttpCall newCall(HttpUrl url);  }
@Test public void should_have_default_settings() throws Exception { HttpClient underTest = newClient(); OkHttpClient okClient = underTest.getUnderlying(); assertThat(okClient.connectTimeoutMillis()).isEqualTo(30_000); assertThat(okClient.readTimeoutMillis()).isEqualTo(300_000); assertThat(okClient.writeTimeoutMillis()).isEqualTo(300_000); assertThat(okClient.followRedirects()).isTrue(); assertThat(okClient.followSslRedirects()).isTrue(); assertThat(okClient.retryOnConnectionFailure()).isTrue(); }
@Test public void should_enable_proxy_authentication_if_system_properties_for_proxy_host_and_credentials_are_defined() { HttpClient.SystemProperties sysProps = mock(HttpClient.SystemProperties.class); when(sysProps.getProperty("http.proxyHost")).thenReturn("proxy.mydomain"); when(sysProps.getProperty("http.proxyUser")).thenReturn("foo"); when(sysProps.getProperty("http.proxyPassword")).thenReturn("bar"); HttpClient underTest = new HttpClient.Builder().setSystemProperties(sysProps).build(); HttpClient.ProxyAuthenticator proxyAuthenticator = (HttpClient.ProxyAuthenticator) underTest.getUnderlying().proxyAuthenticator(); assertThat(proxyAuthenticator.getLogin()).isEqualTo("foo"); assertThat(proxyAuthenticator.getPassword()).isEqualTo("bar"); }
@Test public void should_disable_proxy_authentication_if_system_properties_for_proxy_credentials_are_not_defined() { HttpClient.SystemProperties sysProps = mock(HttpClient.SystemProperties.class); when(sysProps.getProperty("http.proxyHost")).thenReturn("proxy.mydomain"); HttpClient underTest = new HttpClient.Builder().setSystemProperties(sysProps).build(); Authenticator proxyAuthenticator = underTest.getUnderlying().proxyAuthenticator(); assertThat(proxyAuthenticator).isNotInstanceOf(HttpClient.ProxyAuthenticator.class); }
@Test public void should_disable_proxy_authentication_if_proxy_credentials_are_defined_but_not_host() { HttpClient.SystemProperties sysProps = mock(HttpClient.SystemProperties.class); when(sysProps.getProperty("http.proxyUser")).thenReturn("foo"); when(sysProps.getProperty("http.proxyPassword")).thenReturn("bar"); HttpClient underTest = new HttpClient.Builder().setSystemProperties(sysProps).build(); Authenticator proxyAuthenticator = underTest.getUnderlying().proxyAuthenticator(); assertThat(proxyAuthenticator).isNotInstanceOf(HttpClient.ProxyAuthenticator.class); }