import junit.framework.TestCase;
 
public class URLTest extends TestCase {
 
    URL url;
 
    public void setUp () {
        url = new URL ("http://www.example.com/folder");
    }
 
    public void testDomain () {
        assertEquals ("www.example.com", url.getDomain());
    }
 
    public void testPfad () {
        assertEquals ("folder", url.getPath());
    }
 
    public void testProtocol () {
        assertEquals ("http", url.getProtocol());
    }
 
    public void testNoPath () {
        URL urlport = new URL ("http://www.example.com");
        assertEquals ("www.example.com", url.getDomain ());
        assertEquals (80, url.getPort());
    }
 
    public void testPort () {
        URL urlport = new URL ("http://www.example.com:8080/");
        assertEquals (8080, urlport.getPort());
    }
}
 
public class URL {
    String url_str = null;
    String host;
    String path;
    String protocol;
 
    public URL (String url) {
        url_str = url;
 
        String parts[] = url_str.split(":\\/\\/");
        protocol = parts[0];
 
        int idx = parts[1].indexOf('/');
        if (idx == -1) {
            host = parts[1];
            path = null;
        }
        else {
            host = parts[1].substring(0, idx);
            path = parts[1].substring(idx+1);
        }
    }
 
    public String getDomain () {
        return host;
    }
 
    public String getPath () {
        return path;
    }
 
    public String getProtocol () {
        return protocol;
    }
 
    public int getPort () {
        int port;
        int idx = host.indexOf(':');
        if (idx == -1) {
            port = 80;
        }
        else {    
            port = Integer.valueOf(host.substring(idx+1));
        }
        return port;
    }
 
}