• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.core;
18 
19 import junit.framework.TestCase;
20 
21 import java.net.URI;
22 import java.net.URISyntaxException;
23 import android.test.suitebuilder.annotation.SmallTest;
24 
25 public class URITest extends TestCase {
26 
27     @SmallTest
testConstruct()28     public void testConstruct() throws Exception {
29         construct("http://www.google.com/this/is-the/path?query#fragment",
30                 "www.google.com", "/this/is-the/path", true);
31     }
32 
construct(String str, String host, String path, boolean absolute)33     private static void construct(String str, String host, String path, boolean absolute)
34             throws URISyntaxException {
35         URI uri = new URI(str);
36         assertEquals(host, uri.getHost());
37         assertEquals(path, uri.getPath());
38         assertEquals(absolute, uri.isAbsolute());
39     }
40 
41     @SmallTest
testResolve()42     public void testResolve() throws Exception {
43         resolve("http://www.google.com/your",
44                 "mom",
45                 "http://www.google.com/mom");
46     }
47 
resolve(String base, String uri, String expected)48     private static void resolve(String base, String uri, String expected) {
49         URI b = URI.create(base);
50         URI resolved = b.resolve(uri);
51 //        System.out.println("base=" + base + " uri=" + uri
52 //                + " resolved=" + resolved);
53         assertEquals(expected, resolved.toString());
54     }
55 }
56