ProxyTypeTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * 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 */
16
17package tests.api.java.net;
18
19import dalvik.annotation.TestTargets;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24import junit.framework.TestCase;
25
26import java.net.Proxy;
27
28@TestTargetClass(Proxy.Type.class)
29public class ProxyTypeTest extends TestCase {
30
31    @TestTargetNew(
32        level = TestLevel.COMPLETE,
33        notes = "",
34        method = "valueOf",
35        args = {java.lang.String.class}
36    )
37    public void test_valueOf() {
38        Proxy.Type [] types = {Proxy.Type.DIRECT, Proxy.Type.HTTP,
39                Proxy.Type.SOCKS};
40
41        String [] strTypes = {"DIRECT", "HTTP", "SOCKS"};
42
43        for(int i = 0; i < strTypes.length; i++) {
44            assertEquals(types[i], Proxy.Type.valueOf(strTypes[i]));
45        }
46
47        String [] incTypes = {"", "direct", "http", "socks", " HTTP"};
48
49        for(String str:incTypes) {
50            try {
51                Proxy.Type.valueOf(str);
52                fail("IllegalArgumentException was not thrown.");
53            } catch(IllegalArgumentException iae) {
54                //expected
55            }
56        }
57
58        try {
59            Proxy.Type.valueOf(null);
60            fail("NullPointerException was not thrown.");
61        } catch(NullPointerException npe) {
62            //expected
63        }
64    }
65
66    @TestTargetNew(
67        level = TestLevel.COMPLETE,
68        notes = "",
69        method = "values",
70        args = {}
71    )
72    public void test_values() {
73        Proxy.Type [] types = { Proxy.Type.DIRECT, Proxy.Type.HTTP,
74                Proxy.Type.SOCKS };
75
76        Proxy.Type [] result = Proxy.Type.values();
77
78        assertEquals(types.length, result.length);
79
80        for(int i = 0; i < result.length; i++) {
81         assertEquals(types[i], result[i]);
82        }
83    }
84}
85