UrlBuilder { @Nullable public URL build() { if (uriBuilder == null) { return null; } Uri uri = uriBuilder.build(); try { return new URL(uri.toString()); } catch (MalformedURLException e) { Logger.error(e, "Failed to build URL"); return null; } } UrlBuilder(@Nullable String url); @NonNull UrlBuilder appendEncodedPath(@NonNull String path); @NonNull UrlBuilder appendPath(@NonNull String path); @NonNull UrlBuilder appendQueryParameter(@NonNull String key, @NonNull String value); @Nullable URL build();  }
@Test public void testNullUrl() { URL url = new UrlBuilder(null).build(); assertNull(url); }
@Test public void testMalformedUrl() { URL url = new UrlBuilder("notaurl") .build(); assertNull(url); }