@Nullable
    public static URI uriWithTrailingSlash(@Nullable final URI uri) {
        if (uri == null) {
            return null;
        }

        final String path = firstNonNull(uri.getPath(), "/");
        if (path.endsWith("/")) {
            return uri;
        } else {
            try {
                return new URI(
                        uri.getScheme(),
                        uri.getUserInfo(),
                        uri.getHost(),
                        uri.getPort(),
                        path + "/",
                        uri.getQuery(),
                        uri.getFragment());
            } catch (URISyntaxException e) {
                throw new RuntimeException("Could not parse URI.", e);
            }
        }
    }
@Test
    public void uriWithTrailingSlashReturnsNullIfURIIsNull() {
        assertNull(Tools.uriWithTrailingSlash(null));
    }