URLTest.java revision 6c434a1215049a76ba82fea69e8c5aa76cad955b
1/*
2 * Copyright (C) 2010 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 libcore.java.net;
18
19import java.net.URL;
20import junit.framework.TestCase;
21
22public class URLTest extends TestCase {
23    // http://code.google.com/p/android/issues/detail?id=12724
24    public void testExplicitPort() throws Exception {
25        URL url = new URL("http://www.google.com:80/example?language[id]=2");
26        assertEquals("www.google.com", url.getHost());
27        assertEquals(80, url.getPort());
28    }
29
30    public void testHostWithSlashInFragment() throws Exception {
31        URL url = new URL("http://www.google.com#foo/bar");
32        assertEquals("www.google.com", url.getHost());
33        assertEquals("foo/bar", url.getRef());
34        assertEquals(-1, url.getPort());
35    }
36
37    public void testHostWithColonAndSlashInFragment() throws Exception {
38        URL url = new URL("http://www.google.com#foo:bar/baz");
39        assertEquals("www.google.com", url.getHost());
40        assertEquals("foo:bar/baz", url.getRef());
41        assertEquals(-1, url.getPort());
42    }
43
44    public void testEqualsWithNullHost() throws Exception {
45        assertFalse(new URL("file", null, -1, "/a/").equals(new URL("file:/a/")));
46        assertFalse(new URL("http", null, 80, "/a/").equals(new URL("http:/a/")));
47    }
48}
49