@Override
    public OkHttpClient get() {
        final OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
                .retryOnConnectionFailure(true)
                .connectTimeout(connectTimeout.getQuantity(), connectTimeout.getUnit())
                .writeTimeout(writeTimeout.getQuantity(), writeTimeout.getUnit())
                .readTimeout(readTimeout.getQuantity(), readTimeout.getUnit());

        if (trustManagerAndSocketFactoryProvider != null) {
            // always set our own CA, might be overriden in later code
            clientBuilder.sslSocketFactory(trustManagerAndSocketFactoryProvider.getSslSocketFactory(), trustManagerAndSocketFactoryProvider.getTrustManager());
        }

        if (httpProxyUri != null) {
            clientBuilder.proxySelector(proxySelectorProvider.get());

            if (!isNullOrEmpty(httpProxyUri.getUserInfo())) {
                final List<String> list = Splitter.on(":")
                        .limit(2)
                        .splitToList(httpProxyUri.getUserInfo());
                if (list.size() == 2) {
                    clientBuilder.proxyAuthenticator(new ProxyAuthenticator(list.get(0), list.get(1)));
                }
            }
        }

        return clientBuilder.build();
    }
@Test
    public void testDynamicProxy() throws URISyntaxException {
        final String TEST_PROXY = "http://proxy.dummy.org";
        final InetSocketAddress testProxyAddress = new InetSocketAddress(TEST_PROXY, 59001);
        final Proxy testProxy = new Proxy(Proxy.Type.HTTP, testProxyAddress);
        final ProxySelectorProvider proxyProvider = new ProxySelectorProvider(server.url("/").uri(), null);
        ProxySelectorProvider spyProxyProvider = Mockito.spy(proxyProvider);
        final OkHttpClientProvider provider = new OkHttpClientProvider(
                Duration.milliseconds(100L),
                Duration.milliseconds(100L),
                Duration.milliseconds(100L),
                server.url("/").uri(),
                null, spyProxyProvider);

        OkHttpClientProvider spyClientProvider = Mockito.spy(provider);

        final OkHttpClient client = spyClientProvider.get();
        assertThat(client.proxySelector().select(URI.create("http://www.example.com/")))
                .hasSize(1)
                .first()
                .matches(proxy -> proxy.equals(server.toProxyAddress()));

        Mockito.doReturn(testProxyAddress).when(spyProxyProvider).getProxyAddress();
        assertThat(client.proxySelector().select(URI.create("http://www.example.com/")))
                .hasSize(1)
                .first()
                .matches(proxy -> proxy.equals(testProxy));
    }