TwitterOauth { public static String percentEncode(String s) { if (s == null) { return ""; } try { return URLEncoder.encode(s, "UTF-8") .replace("+", "%20").replace("*", "%2A") .replace("%7E", "~"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }  static String getOautHeaderString(Credentials credentials, String method, String baseUrl, Map<String, String> params); static String getOautHeaderString(Credentials credentials, String method, String baseUrl, Map<String, String> params, String nonce, int time); static String getOautHeaderString(String consumerKey, String signature, String accessToken, String nonce, int time); static String percentEncode(String s); static String getSignatureBaseString(String method, String baseUrl, String collectedParams); static String getSigningKey(String consumerSecret, String tokenSecret); static String getHmacSha1(String data, String key); static String collectOauthParams(Map<String, String> params,
                                            String consumerKey,
                                            String nonce,
                                            int timestamp,
                                            String token);  }
@Test public void testPercentEncode() { String input = "Hello Ladies + Gentlemen, a signed OAuth request!"; String expected = "Hello%20Ladies%20%2B%20Gentlemen%2C%20a%20signed%20OAuth%20request%21"; Assert.assertEquals(expected, TwitterOauth.percentEncode(input)); }