Code example for URI

Methods: getAuthority, getPort, parseServerAuthority

0
        URI b = new URI("http://host/a/b/c");
        assertEquals("b/c", a.relativize(b).toString()); // RI assumes a directory
    } 
 
    public void testParseServerAuthorityInvalidAuthority() throws Exception { 
        URI uri = new URI("http://host:-2/");
        assertEquals("host:-2", uri.getAuthority());
        assertNull(uri.getHost());
        assertEquals(-1, uri.getPort());
        try { 
            uri.parseServerAuthority();
            fail();
        } catch (URISyntaxException expected) {
        } 
    } 
 
    public void testParseServerAuthorityOmittedAuthority() throws Exception { 
        URI uri = new URI("http:file");
        uri.parseServerAuthority(); // does nothing!
        assertNull(uri.getAuthority());
        assertNull(uri.getHost());