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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package libcore.java.net;
18 import java.net.InetSocketAddress;
19 import java.net.Proxy;
20 import java.net.SocketAddress;
21 import junit.framework.TestCase;
23 public class OldProxyTest extends TestCase {
25 private SocketAddress address = new InetSocketAddress("127.0.0.1", 1234);
27 public void test_address() {
28 Proxy proxy = new Proxy(Proxy.Type.SOCKS, address);
29 assertEquals(address, proxy.address());
32 new Proxy(Proxy.Type.SOCKS, null);
33 fail("IllegalArgumentException was thrown.");
34 } catch(IllegalArgumentException iae) {
39 public void test_hashCode() {
40 SocketAddress address1 = new InetSocketAddress("127.0.0.1", 1234);
42 Proxy proxy1 = new Proxy(Proxy.Type.HTTP, address1);
43 Proxy proxy2 = new Proxy(Proxy.Type.HTTP, address1);
44 assertTrue(proxy1.hashCode() == proxy2.hashCode());
46 new Proxy(Proxy.Type.SOCKS, address1);
47 Proxy proxy4 = new Proxy(Proxy.Type.SOCKS, address1);
48 assertTrue(proxy1.hashCode() == proxy2.hashCode());
50 assertTrue(proxy1.hashCode() != proxy4.hashCode());
52 SocketAddress address2 = new InetSocketAddress("127.0.0.1", 1235);
54 Proxy proxy5 = new Proxy(Proxy.Type.SOCKS, address1);
55 Proxy proxy6 = new Proxy(Proxy.Type.SOCKS, address2);
56 assertTrue(proxy5.hashCode() != proxy6.hashCode());
59 public void test_type() {
61 Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
62 assertEquals(Proxy.Type.HTTP, proxy.type());
64 proxy = new Proxy(Proxy.Type.SOCKS, address);
65 assertEquals(Proxy.Type.SOCKS, proxy.type());
67 proxy = Proxy.NO_PROXY;
68 assertEquals(Proxy.Type.DIRECT, proxy.type());