UrlBuilder { public UrlBuilder addPathSegment(@Nonnull String segment) { UrlBuilder b = new UrlBuilder(this); if (! path.endsWith("/") && ! segment.startsWith("/")) { segment = "/" + segment; } b.path = path + segment; return b; } private  UrlBuilder(UrlEncoder encoder, String scheme, String userInfo, String host, int port, String path,
	    HashMap<String, String> queryParams, String fragment); private  UrlBuilder(UrlBuilder other); static UrlBuilder fromUrl(URI baseUri); static UrlBuilder fromUrl(URL baseUrl); static UrlBuilder fromUrl(String baseUrl); URI build(); UrlBuilder scheme(@Nonnull String scheme); UrlBuilder userInfo(@Nonnull String userInfo); UrlBuilder host(@Nonnull String host); UrlBuilder port(int port); UrlBuilder replacePath(@Nullable String path); UrlBuilder addPathSegment(@Nonnull String segment); UrlBuilder queryParam(@Nonnull String key, @Nullable String value); UrlBuilder queryParamUrl(@Nonnull String key, @Nullable String value); UrlBuilder queryParam(@Nonnull String key, @Nullable String value, boolean overwrite); UrlBuilder queryParamUrl(@Nonnull String key, @Nullable String value, boolean overwrite); UrlBuilder removeQueryParams(); UrlBuilder fragment(@Nullable String fragment);  }
@Test public void addPathSegment() throws URISyntaxException { UrlBuilder b = UrlBuilder.fromUrl("http: b = b.addPathSegment("/foo"); assertEquals(b.build(), new URI("http: b = b.addPathSegment("bar/"); assertEquals(b.build(), new URI("http: b = b.addPathSegment("/quack"); assertEquals(b.build(), new URI("http: }