Home | History | Annotate | Download | only in net
      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 libcore.java.net;
     18 
     19 import java.net.URI;
     20 import java.net.URISyntaxException;
     21 import junit.framework.TestCase;
     22 
     23 public class OldAndroidURITest extends TestCase {
     24 
     25     public void testConstruct() throws Exception {
     26         construct("http://www.google.com/this/is-the/path?query#fragment",
     27                 "www.google.com", "/this/is-the/path", true);
     28     }
     29 
     30     private static void construct(String str, String host, String path, boolean absolute)
     31             throws URISyntaxException {
     32         URI uri = new URI(str);
     33         assertEquals(host, uri.getHost());
     34         assertEquals(path, uri.getPath());
     35         assertEquals(absolute, uri.isAbsolute());
     36     }
     37 
     38     public void testResolve() throws Exception {
     39         resolve("http://www.google.com/your",
     40                 "mom",
     41                 "http://www.google.com/mom");
     42     }
     43 
     44     private static void resolve(String base, String uri, String expected) {
     45         URI b = URI.create(base);
     46         URI resolved = b.resolve(uri);
     47         assertEquals(expected, resolved.toString());
     48     }
     49 }
     50