URLTest.java revision 8fd0225a5c3918fe0cd4680258388985c25533e5
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