1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package libcore.java.net; 17 18import java.net.InetSocketAddress; 19import java.net.Proxy; 20import java.net.SocketAddress; 21import junit.framework.TestCase; 22 23public class OldProxyTest extends TestCase { 24 25 private SocketAddress address = new InetSocketAddress("127.0.0.1", 1234); 26 27 public void test_address() { 28 Proxy proxy = new Proxy(Proxy.Type.SOCKS, address); 29 assertEquals(address, proxy.address()); 30 31 try { 32 new Proxy(Proxy.Type.SOCKS, null); 33 fail("IllegalArgumentException was thrown."); 34 } catch(IllegalArgumentException iae) { 35 //expected 36 } 37 } 38 39 public void test_hashCode() { 40 SocketAddress address1 = new InetSocketAddress("127.0.0.1", 1234); 41 42 Proxy proxy1 = new Proxy(Proxy.Type.HTTP, address1); 43 Proxy proxy2 = new Proxy(Proxy.Type.HTTP, address1); 44 assertTrue(proxy1.hashCode() == proxy2.hashCode()); 45 46 new Proxy(Proxy.Type.SOCKS, address1); 47 Proxy proxy4 = new Proxy(Proxy.Type.SOCKS, address1); 48 assertTrue(proxy1.hashCode() == proxy2.hashCode()); 49 50 assertTrue(proxy1.hashCode() != proxy4.hashCode()); 51 52 SocketAddress address2 = new InetSocketAddress("127.0.0.1", 1235); 53 54 Proxy proxy5 = new Proxy(Proxy.Type.SOCKS, address1); 55 Proxy proxy6 = new Proxy(Proxy.Type.SOCKS, address2); 56 assertTrue(proxy5.hashCode() != proxy6.hashCode()); 57 } 58 59 public void test_type() { 60 61 Proxy proxy = new Proxy(Proxy.Type.HTTP, address); 62 assertEquals(Proxy.Type.HTTP, proxy.type()); 63 64 proxy = new Proxy(Proxy.Type.SOCKS, address); 65 assertEquals(Proxy.Type.SOCKS, proxy.type()); 66 67 proxy = Proxy.NO_PROXY; 68 assertEquals(Proxy.Type.DIRECT, proxy.type()); 69 } 70} 71