### Question:
UriUtils { public static void checkUrlIsValid(String url) throws IllegalArgumentException { logger.debug("Url is : {}",url); boolean urlIsValid; Pattern p = Pattern.compile(URL_PATTERN); Matcher m = p.matcher(url); if (!m.matches()) { p = Pattern.compile(IP_ADDRESS_PATTERN); m = p.matcher(url); urlIsValid = m.matches(); }else{ urlIsValid = true; } if(!urlIsValid){ throw new IllegalArgumentException("Url is not valid"); } URI.create(url); logger.debug("urlIsValid : {}",urlIsValid); }  static void checkUrlIsValid(String url); final static String URL_PATTERN; final static String IP_ADDRESS_PATTERN; }### Answer:
@Test public void checkUriIsValidTest() { String url = "http: UriUtils.checkUrlIsValid(url); url = "https: UriUtils.checkUrlIsValid(url); url = "http: UriUtils.checkUrlIsValid(url); url = "https: UriUtils.checkUrlIsValid(url); url = "http: UriUtils.checkUrlIsValid(url); url = "http: UriUtils.checkUrlIsValid(url); url = "http: UriUtils.checkUrlIsValid(url); url = "https: UriUtils.checkUrlIsValid(url); }
@Test(expected=IllegalArgumentException.class) public void spaceIsNotValidTest(){ String url = "http: UriUtils.checkUrlIsValid(url); }
@Test(expected=IllegalArgumentException.class) public void noHttpIsNotValidTest(){ String url = "badurl.net"; UriUtils.checkUrlIsValid(url); }
@Test(expected=IllegalArgumentException.class) public void plainStringIsNotValidTest(){ String url = "toto"; UriUtils.checkUrlIsValid(url); }