public static String encode(String plain) {
        Preconditions.checkNotNull(plain, "Cannot encode null object");
        String encoded;
        try {
            encoded = URLEncoder.encode(plain, CHARSET);
        } catch (UnsupportedEncodingException uee) {
            throw new OAuthException("Charset not found while encoding string: " + CHARSET, uee);
        }
        for (Map.Entry<String, String> rule : ENCODING_RULES.entrySet()) {
            encoded = applyRule(encoded, rule.getKey(), rule.getValue());
        }
        return encoded;
    }
@Test
    public void shouldPercentEncodeCorrectlyTwitterCodingExamples() {
        // These tests are part of the Twitter dev examples here
        // -> https://dev.twitter.com/docs/auth/percent-encoding-parameters
        final String[] sources = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"};
        final String[] encoded = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21",
            "Dogs%2C%20Cats%20%26%20Mice"};

        for (int i = 0; i < sources.length; i++) {
            assertEquals(encoded[i], OAuthEncoder.encode(sources[i]));
        }
    }