UrlUtil { protected static String encode(String url) { StringBuilder encoder = new StringBuilder(); for (char chr : url.toCharArray()) { byte chrByte = (byte) chr; if ((chrByte <= 32 || chrByte >= 127 || chr == '#' || chr == '%')) { encoder.append(String.format("%%%02X", chrByte)); } else { encoder.append(chr); } } return encoder.toString(); } private  UrlUtil();   }
@Test(dataProvider = "getEncodeStrings") public void testEncode(String input, String expectedEncodedString) { Assert.assertEquals(UrlUtil.encode(input), expectedEncodedString); }