OldAuthenticatorTest.java revision 1f8243e3d2b5a3f8e0398c304d1dea0395cbc368
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 */
16
17package libcore.java.net;
18
19import java.net.Authenticator;
20import java.net.InetAddress;
21import java.net.PasswordAuthentication;
22import java.net.URL;
23import java.net.UnknownHostException;
24import junit.framework.TestCase;
25
26public class OldAuthenticatorTest extends TestCase {
27
28    public void test_setDefault() throws UnknownHostException {
29        InetAddress addr = InetAddress.getLocalHost();
30        PasswordAuthentication  pa = Authenticator.requestPasswordAuthentication(
31                addr, 8080, "http", "promt", "HTTP");
32        assertNull(pa);
33
34        MockAuthenticator mock = new MockAuthenticator();
35        Authenticator.setDefault(mock);
36
37        addr = InetAddress.getLocalHost();
38        pa = Authenticator.requestPasswordAuthentication(addr, 80, "http", "promt", "HTTP");
39        assertNull(pa);
40
41        Authenticator.setDefault(null);
42    }
43
44    public void test_Constructor() {
45        MockAuthenticator ma = new MockAuthenticator();
46        assertNull(ma.getRequestingURL());
47        assertNull(ma.getRequestorType());
48    }
49
50    public void test_getPasswordAuthentication() {
51        MockAuthenticator ma = new MockAuthenticator();
52        assertNull(ma.getPasswordAuthentication());
53    }
54
55    class MockAuthenticator extends Authenticator {
56        public URL getRequestingURL() {
57            return super.getRequestingURL();
58        }
59
60        public Authenticator.RequestorType getRequestorType() {
61            return super.getRequestorType();
62        }
63
64        public PasswordAuthentication getPasswordAuthentication() {
65            return super.getPasswordAuthentication();
66        }
67    }
68}
69