Source:
public void testUsingProxySelector ( ) throws java.lang.Exception { org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer server = new org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer ( "server" ) ; org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer proxy = new org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer ( "proxy" ) ; java.net.URL url = new java.net.URL ( ( "http://localhost:" + ( server.port ( ) ) ) ) ; java.net.ProxySelector defPS = java.net.ProxySelector.getDefault ( ) ; java.net.ProxySelector.setDefault ( new org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.TestProxySelector ( server.port ( ) , proxy.port ( ) ) ) ; try { java.net.HttpURLConnection connection = ( ( java.net.HttpURLConnection ) ( url.openConnection ( ) ) ) ; connection.setConnectTimeout ( 2000 ) ; connection.setReadTimeout ( 2000 ) ; server.start ( ) ; synchronized ( org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound ) { if ( ! ( server.started ) ) org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound.wait ( 5000 ) ; } proxy.start ( ) ; synchronized ( org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound ) { if ( ! ( proxy.started ) ) org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound.wait ( 5000 ) ; } connection.connect ( ) ; server.join ( ) ; proxy.join ( ) ; assertTrue ( "Connection does not use proxy" , connection.usingProxy ( ) ) ; assertTrue ( "Proxy server was not used" , proxy.accepted ) ; } finally { java.net.ProxySelector.setDefault ( defPS ) ; } }

Target:
public void testUsingProxySelector ( ) throws java.lang.Exception { org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer server = new org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer ( "server" ) ; org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer proxy = new org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.MockServer ( "proxy" ) ; java.net.URL url = new java.net.URL ( ( "http://localhost:" + ( server.port ( ) ) ) ) ; java.net.ProxySelector defPS = java.net.ProxySelector.getDefault ( ) ; java.net.ProxySelector.setDefault ( new org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.TestProxySelector ( server.port ( ) , proxy.port ( ) ) ) ; try { java.net.HttpURLConnection connection = ( ( java.net.HttpURLConnection ) ( url.openConnection ( ) ) ) ; connection.setConnectTimeout ( 2000 ) ; connection.setReadTimeout ( 2000 ) ; server.start ( ) ; synchronized ( org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound ) { if ( ! ( server.started ) ) org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound.wait ( 5000 ) ; } proxy.start ( ) ; synchronized ( org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound ) { if ( ! ( proxy.started ) ) org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest.bound.wait ( 5000 ) ; } connection.connect ( ) ; server.join ( ) ; proxy.join ( ) ; assertTrue ( "Connection does not use proxy" , connection.usingProxy ( ) ) ; assertTrue ( "Proxy server was not used" , proxy.accepted ) ; connection.disconnect ( ) ; assertTrue ( "usingProxy broken after disconnect" , connection.usingProxy ( ) ) ; } finally { java.net.ProxySelector.setDefault ( defPS ) ; } }