### Question:
UrlUtils { public static String encodePath(String fileName, boolean withRoot) { fileName = fileName.replaceAll("\\\\", "/"); StringBuilder ret = new StringBuilder(); String[] fileNames = fileName.split("/"); for (int index = 0; index < fileNames.length; index++) { if (!fileNames[index].equals("")) { if (withRoot || index != 0) { ret.append("/"); } try { ret.append(URLEncoder.encode(fileNames[index], "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return ret.toString(); } private  UrlUtils(); static boolean isUrlOK(String str); static String appendParams(String url, Map<?, ?> params); static StringBuilder appendParams(StringBuilder url, Map<?, ?> params, String charset); static String appendParams(String url, Map<?, ?> params, String charset); static String encodePath(String fileName, boolean withRoot);  }### Answer:
@Test(dataProvider = "encodePath") public void testEncodePath(String fileName, boolean withRoot, String expected) { String str = UrlUtils.encodePath(fileName, withRoot); Assert.assertEquals(str, expected); }