ProxyProvider { public final ProxyHandler newProxyHandler() { InetSocketAddress proxyAddr = this.address.get(); final boolean b = Objects.nonNull(username) && Objects.nonNull(password); String username = this.username; String password = b ? this.password.apply(username) : null; final ProxyHandler proxyHandler; switch (this.type) { case HTTP: proxyHandler = b ? new HttpProxyHandler(proxyAddr, username, password, this.httpHeaders.get()) : new HttpProxyHandler(proxyAddr, this.httpHeaders.get()); break; case SOCKS4: proxyHandler = Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) : new Socks4ProxyHandler(proxyAddr); break; case SOCKS5: proxyHandler = b ? new Socks5ProxyHandler(proxyAddr, username, password) : new Socks5ProxyHandler(proxyAddr); break; default: throw new IllegalArgumentException("Proxy type unsupported : " + this.type); } proxyHandler.setConnectTimeoutMillis(connectTimeoutMillis); return proxyHandler; } ProxyProvider(ProxyProvider.Build builder); static ProxyProvider.TypeSpec builder(); final Proxy getType(); final Supplier<? extends InetSocketAddress> getAddress(); final Predicate<SocketAddress> getNonProxyHostsPredicate(); final ProxyHandler newProxyHandler(); boolean shouldProxy(SocketAddress address); void addProxyHandler(Channel channel); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void connectTimeoutWithNonPositiveValue() { assertEquals(0, createConnectTimeoutProxy(0).newProxyHandler().connectTimeoutMillis()); assertEquals(0, createConnectTimeoutProxy(-1).newProxyHandler().connectTimeoutMillis()); }