### Question:
HttpUtils { public static String urlEncode(final String value, final boolean path) { if (value == null) { return ""; } try { final String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); final Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); final StringBuffer buffer = new StringBuffer(encoded.length()); while (matcher.find()) { String replacement = matcher.group(0); if ("+".equals(replacement)) { replacement = "%20"; } else if ("*".equals(replacement)) { replacement = "%2A"; } else if ("%7E".equals(replacement)) { replacement = "~"; } else if (path && "%2F".equals(replacement)) { replacement = "/"; } matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); } catch (final UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }  static String urlEncode(final String value, final boolean path); static String urlDecode(final String value); static boolean isUsingNonDefaultPort(URI uri); static boolean usePayloadForQueryParameters(Request<?> request); static String encodeParameters(Request<?> request); static String appendUri(String baseUri, String path); static String appendUri(final String baseUri, String path,
            final boolean escapeDoubleSlash); static InputStream fetchFile(
            final URI uri,
            final ClientConfiguration config);  }### Answer:
@Test public void testEncodeNull() { Assert.assertEquals("urlEncode(null) returned something unexpected", "", HttpUtils.urlEncode(null, false)); }
@Test public void testEncodeEmptyString() { Assert.assertEquals("urlEncode(\"\") returned something unexpected", "", HttpUtils.urlEncode("", false)); }
@Test public void testNoEncoding() { final String test = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "-_.~"; Assert.assertEquals("urlEncode(\"" + test + "\") returned something " + "unexpected", test, HttpUtils.urlEncode(test, false)); }
@Test public void testNoEncodingPath() { final String test = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "-_.~/"; Assert.assertEquals("urlEncode(\"" + test + "\") returned something " + "unexpected", test, HttpUtils.urlEncode(test, true)); }