@Test
public void actsAsUrlFormParameterEscaper() {

    try {
        UrlEscapeUtils.escape(null);
        fail("Escaping null string should throw exception");
    } catch (NullPointerException x) {
        // pass
    }
    // 0-9, A-Z, a-z should be left unescaped
    assertUnescaped('a');
    assertUnescaped('z');
    assertUnescaped('A');
    assertUnescaped('Z');
    assertUnescaped('0');
    assertUnescaped('9');
    // Unreserved characters used in java.net.URLEncoder
    assertUnescaped('-');
    assertUnescaped('_');
    assertUnescaped('.');
    assertUnescaped('*');
    assertEscaping("%3D", '=');
    assertEscaping("%2F", '/');
    assertEscaping("%00", '\u0000');       // nul
    assertEscaping("%7F", '\u007f');       // del
    assertEscaping("%C2%80", '\u0080');    // xx-00010,x-000000
    assertEscaping("%DF%BF", '\u07ff');    // xx-11111,x-111111
    assertEscaping("%E0%A0%80", '\u0800'); // xxx-0000,x-100000,x-00,0000
    assertEscaping("%EF%BF%BF", '\uffff'); // xxx-1111,x-111111,x-11,1111
    assertUnicodeEscaping("%F0%90%80%80", '\uD800', '\uDC00');
    assertUnicodeEscaping("%F4%8F%BF%BF", '\uDBFF', '\uDFFF');
    assertThat(UrlEscapeUtils.escape("")).isEqualTo("");
    assertThat(UrlEscapeUtils.escape("safestring")).isEqualTo("safestring");
    assertThat(UrlEscapeUtils.escape("embedded\0null")).isEqualTo("embedded%00null");
    assertThat(UrlEscapeUtils.escape("max\uffffchar")).isEqualTo("max%EF%BF%BFchar");
    // Specified as safe by RFC 2396 but not by java.net.URLEncoder.
    assertEscaping("%21", '!');
    assertEscaping("%28", '(');
    assertEscaping("%29", ')');
    assertEscaping("%7E", '~');
    assertEscaping("%27", '\'');
    // Plus for spaces
    assertEscaping("%20", ' ');
    assertEscaping("%2B", '+');
    assertThat(UrlEscapeUtils.escape("safe with spaces")).isEqualTo("safe%20with%20spaces");
    assertThat(UrlEscapeUtils.escape("foo@bar.com")).isEqualTo("foo%40bar.com");
}