UriUtils { public static URI buildNewURI( URI referenceUri, String uriSuffix ) throws URISyntaxException { if( uriSuffix == null ) throw new IllegalArgumentException( "The URI suffix cannot be null." ); uriSuffix = uriSuffix.replaceAll( "\\\\", "/" ); URI importUri = null; try { importUri = urlToUri( new URL( uriSuffix )); } catch( Exception e ) { try { if( ! referenceUri.toString().endsWith( "/" ) && ! uriSuffix.startsWith( "/" )) referenceUri = new URI( referenceUri.toString() + "/" ); importUri = referenceUri.resolve( new URI( null, uriSuffix, null )); } catch( Exception e2 ) { String msg = "An URI could not be built from the URI " + referenceUri.toString() + " and the suffix " + uriSuffix + "."; throw new URISyntaxException( msg, e2.getMessage()); } } return importUri.normalize(); } private  UriUtils(); static URI urlToUri( URL url ); static URI urlToUri( String urlAsString ); static URI buildNewURI( URI referenceUri, String uriSuffix );  }
@Test public void testBuildNewURI_1() throws Exception { String suffix = "http: Assert.assertEquals( new URI( suffix ), UriUtils.buildNewURI( null, suffix )); }
@Test public void testBuildNewURI_2() throws Exception { String url = "http: String suffix = "readme.txt"; Assert.assertEquals( new URI( url + suffix ), UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test public void testBuildNewURI_3() throws Exception { String url = "http: String suffix = "/readme.txt"; Assert.assertEquals( new URI( url + suffix ), UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test public void testBuildNewURI_4() throws Exception { String url = "http: String suffix = "readme.txt"; Assert.assertEquals( new URI( url + "/" + suffix ), UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test public void testBuildNewURI_5() throws Exception { String url = "http: String suffix = "readme.txt"; Assert.assertEquals( new URI( url + "/" + suffix ), UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test public void testBuildNewURI_6() throws Exception { String url = "http: String suffix = "../readme.txt"; Assert.assertEquals( new URI( "http: UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test public void testBuildNewURI_7() throws Exception { String url = "http: String suffix = "./readme.txt"; Assert.assertEquals( new URI( "http: UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test public void testBuildNewURI_8() throws Exception { String url = "http: String suffix = "f1/f2/f3/readme.txt"; Assert.assertEquals( new URI( "http: UriUtils.buildNewURI( new URI( url ), suffix )); }
@Test( expected = IllegalArgumentException.class ) public void testBuildNewURI_9() throws Exception { UriUtils.buildNewURI( new URI( "http: }
@Test( expected = URISyntaxException.class ) public void testBuildNewURI_10() throws Exception { String url = "http: String suffix = ":f1/readme.txt"; UriUtils.buildNewURI( new URI( url ), suffix ); }