import junit.framework.TestCase;
 
public class UrlTest extends TestCase {
 
    protected void setUp() throws Exception {
        super.setUp();
    }
 
    public void testEmptyUrl() throws Exception {
        Url url = new Url("");
        assertEquals("Ungültige Url -- Leere Url", url.getProtocol());
    }
 
    public void testVaildProtocols() throws Exception {
        Url urlHttp    = new Url("http://www.mactechnews.de");
        Url urlHttps    = new Url("https://www.ccc.de");
        Url urlFtp    = new Url("ftp://ftp.xyz.net");
 
        assertEquals("http",  urlHttp.getProtocol());
        assertEquals("https", urlHttps.getProtocol());
        assertEquals("ftp",   urlFtp.getProtocol());
    }
 
    public void testInvalidUrls() throws Exception {
        Url url = new Url("://www.web.de");
        assertEquals("Ungültige Url -- Keine Prokollangabe", url.getProtocol());
    }
 
    public void testNullUrl() throws Exception {
        Url urlNull    = new Url(null);
        assertEquals("Ungültige Url -- Systemfehler", urlNull.getProtocol());
    }
}
 
 
public class Url {
 
    private static final String EMPTY_ERROR = "Ungültige Url -- Leere Url";
    private static final String PROTOCOL_ERROR = "Ungültige Url -- Keine Prokollangabe";
 
    private String locatorString;
 
    public Url(String path) {
        this.locatorString = path;
    }
 
    public String getProtocol() {
        String[] halfs = locatorString.split("://");
 
        if(halfs.length <= 1) {
            return EMPTY_ERROR;
        }
        if("".equals(halfs[0])) {
            return PROTOCOL_ERROR;
        }
        return halfs[0];
    }
 
}