@Nullable
    public static URI normalizeURI(@Nullable final URI uri, String scheme, int port, String path) {
        return Optional.ofNullable(uri)
                .map(u -> getUriWithScheme(u, scheme))
                .map(u -> getUriWithPort(u, port))
                .map(u -> getUriWithDefaultPath(u, path))
                .map(Tools::uriWithTrailingSlash)
                .map(URI::normalize)
                .orElse(null);
    }
@Test
    public void normalizeURIAddsSchemaAndPortAndPathWithTrailingSlash() {
        final URI uri = URI.create("foobar://example.com");
        assertEquals(URI.create("quux://example.com:1234/foobar/"), Tools.normalizeURI(uri, "quux", 1234, "/foobar"));
    }