@Test
public void testToString() throws Exception {

    URL url = new URL();
    
    url.setProtocol("p");
    Assert.assertEquals("p://", url.toString());
    url.setHost("h");
    Assert.assertEquals("p://h", url.toString());
    url.setPort(80);
    Assert.assertEquals("p://h:80", url.toString());
    url.setPath("/");
    Assert.assertEquals("p://h:80/", url.toString());
    url.setUsername("u");
    Assert.assertEquals("p://u@h:80/", url.toString());
    url.setPassword("p");
    Assert.assertEquals("p://u:p@h:80/", url.toString());
    url.setPort(null);
    Assert.assertEquals("p://u:p@h/", url.toString());
    url.setUsername(null);
    Assert.assertEquals("p://h/", url.toString());
    url.setPath(null);
    Assert.assertEquals("p://h", url.toString());
}