URIUtil { public static URI getURIFromRequestUrl(String source) { try { return new URI(source); } catch (URISyntaxException e) { if (BuildConfig.DEBUG) Log.d(TAG, "Source is not encoded, encoding now"); } try { URL url = new URL(source); return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); } catch (MalformedURLException | URISyntaxException e) { throw new IllegalArgumentException(e); } } private  URIUtil(); static URI getURIFromRequestUrl(String source);  }
@Test public void testGetURIFromRequestUrlShouldNotEncode() { final String testUrl = "http: assertEquals(testUrl, URIUtil.getURIFromRequestUrl(testUrl).toString()); }
@Test public void testGetURIFromRequestUrlShouldEncode() { final String testUrl = "http: final String expected = "http: assertEquals(expected, URIUtil.getURIFromRequestUrl(testUrl).toString()); }