### Question:
ValidationUtility { public static void validateURL(String url, String controlGroup) throws ValidationException { if (!(controlGroup.equalsIgnoreCase("M") || controlGroup.equalsIgnoreCase("E")) && url.startsWith("file:")) { throw new ValidationException( "Malformed URL (file: not allowed for control group " + controlGroup + ") " + url); } try { new URL(url); } catch (MalformedURLException e) { if (url.startsWith(DatastreamManagedContent.UPLOADED_SCHEME)) { return; } throw new ValidationException("Malformed URL: " + url, e); } }  static void validateURL(String url, String controlGroup); static void setPolicyParser(PolicyParser parser); static void setFeslPolicyParser(PolicyParser parser); static void setValidateFeslPolicy(boolean validate); static void validateReservedDatastreams(DOReader reader); static void validateReservedDatastream(PID pid,
                                                  String dsId,
                                                  Datastream ds);  }### Answer:
@Test public void testValidUrls() throws Exception { String[] urls_managed = {"http: "http: "uploaded: "file: "file:/etc/passwd" }; for (String url : urls_managed) { ValidationUtility.validateURL(url,"M"); } String[] urls = {"http: "http: "uploaded: }; for (String url : urls) { ValidationUtility.validateURL(url,"M"); } }
@Test public void testInvalidUrls(){ String[] urls_management = {"", "a", "temp: "copy: "temp: "temp: "/etc/passwd", "../../etc/passwd"}; for (String url : urls_management) { try { ValidationUtility.validateURL(url,"M"); } catch (Exception e) { assertTrue("Expected Exception of type " + ValidationException.class.getName() + " but got: " + e.getClass().getName(), e.getClass().getName() .equals(ValidationException.class.getName())); continue; } fail("Expected " + ValidationException.class.getName() + " for URL:" + url + " but got none"); } String[] urls = {"", "a", "temp: "copy: "temp: "temp: "/etc/passwd", "../../etc/passwd", "file: "file:/etc/passwd"}; for (String url : urls) { try { ValidationUtility.validateURL(url,"R"); } catch (Exception e) { assertTrue("Expected Exception of type " + ValidationException.class.getName() + " but got: " + e.getClass().getName(), e.getClass().getName() .equals(ValidationException.class.getName())); continue; } fail("Expected " + ValidationException.class.getName() + " for URL:" + url + " but got none"); } }