/**
   * Tests FileURL's getters and setters.
   *
   * @throws MalformedURLException should not happen
   */
  @Test
  public void testAccessors() throws MalformedURLException {
    FileURL url = getRootURL();

    String scheme = getScheme();
    Credentials credentials = new Credentials("login", "password");
    String host = "host";
    int port = 10000;
    String path = getSchemePath("/path/to");
    String query = "query";

    url.setScheme(scheme);
    url.setCredentials(credentials);
    url.setHost(host);
    url.setPort(port);
    url.setPath(path);
    url.setQuery(query);
    url.setProperty("name", "value");

    assert scheme.equals(url.getScheme());
    assert credentials.equals(url.getCredentials(), true);
    assert host.equals(url.getHost());
    assert port == url.getPort();
    assert path.equals(url.getPath());
    assert query.equals(url.getQuery());
    assert "to".equals(url.getFilename());
    assert "value".equals(url.getProperty("name"));

    // Test null values

    url.setCredentials(null);
    url.setHost(null);
    url.setPort(-1);
    url.setPath("/");
    url.setQuery(null);
    url.setProperty("name", null);

    assert scheme.equals(url.getScheme());
    assert url.getCredentials() == null;
    assert !url.containsCredentials();
    assert url.getHost() == null;
    assert -1 == url.getPort();
    assert "/".equals(url.getPath());
    assert url.getQuery() == null;
    assert url.getFilename() == null;
    assert url.getProperty("name") == null;
    assert (scheme + "://").equals(url.toString(true, false));

    // Path cannot be null, the path is supposed to be "/" if a null or empty value is specified
    url.setPath(null);
    assert "/".equals(url.getPath());
    url.setPath("");
    assert "/".equals(url.getPath());

    // Path must always start with a leading '/', if the specified does not then a '/' is
    // automatically added
    url.setPath("path/to");
    assert "/path/to".equals(url.getPath());
  }
  /**
   * Ensures that FileURL#getParent() works as expected.
   *
   * @throws MalformedURLException should not happen
   */
  @Test
  public void testParent() throws MalformedURLException {
    FileURL url = getURL("login", "password", "host", 10000, "/path/to", "query&param=value");
    url.setProperty("key", "value");

    FileURL parentURL = url.getParent();

    // Test path and filename
    assertPathEquals(getSchemePath("/path/"), parentURL);
    assert "path".equals(parentURL.getFilename());

    // Assert that schemes, hosts and ports match
    assert url.getScheme().equals(parentURL.getScheme());
    assert url.getHost().equals(parentURL.getHost());
    assert url.getPort() == parentURL.getPort();

    // Assert that credentials match
    assert url.getCredentials().equals(parentURL.getCredentials());
    assert url.getLogin().equals(parentURL.getLogin());
    assert url.getPassword().equals(parentURL.getPassword());

    // Assert that the sample property is in the parent URL
    assert "value".equals(parentURL.getProperty("key"));

    // Assert that handlers match
    assert url.getHandler().equals(parentURL.getHandler());

    // Assert that the query part is null
    assert parentURL.getQuery() == null;

    // One more time, the parent path is now "/"

    url = parentURL;
    parentURL = url.getParent();

    // Test path and filename
    assertPathEquals(getSchemePath("/"), parentURL);
    assert parentURL.getFilename() == null;

    // The parent URL should now be null

    // Test path and filename
    url = parentURL;
    assert url.getParent() == null;
  }
  /**
   * Tests {@link FileURL#clone()}.
   *
   * @throws MalformedURLException should not happen
   */
  @Test
  public void testClone() throws MalformedURLException {
    FileURL url = getURL("login", "password", "host", 10000, "/path/to", "query");
    url.setProperty("name", "value");

    FileURL clonedURL = (FileURL) url.clone();

    // Assert that both instances are equal according to FileURL#equals
    assertEquals(url, clonedURL);

    // Assert that both URL's string representations (with credentials) are equal
    assert url.toString(true).equals(clonedURL.toString(true));

    // Assert that both instances are not one and the same
    assert url != clonedURL;

    // Assert that the property has survived the cloning
    assert "value".equals(clonedURL.getProperty("name"));
  }