Util { public static String urlEncode(String str) { try { String encodeForForm = URLEncoder.encode(str, "UTF-8"); String encodeForUrl = encodeForForm.replace("+", "%20"); return encodeForUrl; } catch (UnsupportedEncodingException e) { throw new IllegalStateException("JVM does not support UTF-8"); } }  static String toJson(Object obj); static T fromJson(String json, Class<T> clazz); static T fromJson(Reader in, TypeReference<T> typeReference); static String urlEncode(String str); static String urlEncodeQuery(String str); static StringBuilder getContextUrlString(String baseUrl, String context); static void ensureEndsWithSlash(StringBuilder str); static long copyStream(InputStream input, OutputStream output, boolean closeStreams); static String slurpStream(InputStream input, String encoding); static String read(File file); static void write(String string, File file); static String base64Encode(String plainTextString); static String getMachineId(); static String getContainerId(); static String extractDockerContainerIdFromString(String s); static Properties extractPropertiesFromExpression(String expression);  }
@Test public void encodeUrlSpace() { String encoded = Util.urlEncode("space should be a percent20"); Assert.assertEquals("space%20should%20be%20a%20percent20", encoded); }