UriComponent { public static String contextualEncode(final String s, final Type t) { return _encode(s, t, false, true); } private  UriComponent(); static void validate(final String s, final Type t); static void validate(final String s, final Type t, final boolean template); static boolean valid(final String s, final Type t); static boolean valid(final String s, final Type t, final boolean template); static String contextualEncode(final String s, final Type t); static String contextualEncode(final String s, final Type t, final boolean template); static String encode(final String s, final Type t); static String encode(final String s, final Type t, final boolean template); static String encodeTemplateNames(String s); static String decode(final String s, final Type t); static MultivaluedMap<String, String> decodeQuery(final URI u, final boolean decode); static MultivaluedMap<String, String> decodeQuery(final String q, final boolean decode); static MultivaluedMap<String, String> decodeQuery(final String q, final boolean decodeNames,
                                                             final boolean decodeValues); static List<PathSegment> decodePath(final URI u, final boolean decode); static List<PathSegment> decodePath(final String path, final boolean decode); static void decodePathSegment(final List<PathSegment> segments, final String segment, final boolean decode); static MultivaluedMap<String, String> decodeMatrix(final String pathSegment, final boolean decode); static boolean isHexCharacter(final char c); static String fullRelativeUri(final URI uri);  }
@Test public void testContextualEncodePath() { assertEquals("/a/b/c", UriComponent.contextualEncode("/a/b/c", UriComponent.Type.PATH)); assertEquals("/a%20/b%20/c%20", UriComponent.contextualEncode("/a /b /c ", UriComponent.Type.PATH)); assertEquals("/copyright%C2%A9", UriComponent.contextualEncode("/copyright\u00a9", UriComponent.Type.PATH)); assertEquals("/thumbsup%F0%9F%91%8D", UriComponent.contextualEncode("/thumbsup\ud83d\udc4d", UriComponent.Type.PATH)); assertEquals("/a%20/b%20/c%20", UriComponent.contextualEncode("/a%20/b%20/c%20", UriComponent.Type.PATH)); assertEquals("/copyright%C2%A9", UriComponent.contextualEncode("/copyright%C2%A9", UriComponent.Type.PATH)); assertEquals("/thumbsup%F0%9F%91%8D", UriComponent.contextualEncode("/thumbsup%F0%9F%91%8D", UriComponent.Type.PATH)); }
@Test public void testContextualEncodeQuery() { assertEquals("a%20b%20c.-%2A_=+&%25xx%20", UriComponent.contextualEncode("a b c.-*_=+&%xx%20", UriComponent.Type.QUERY)); assertEquals("a+b+c.-%2A_%3D%2B%26%25xx%20", UriComponent.contextualEncode("a b c.-*_=+&%xx%20", UriComponent.Type.QUERY_PARAM)); assertEquals("a%20b%20c.-%2A_%3D%2B%26%25xx%20", UriComponent.contextualEncode("a b c.-*_=+&%xx%20", UriComponent.Type.QUERY_PARAM_SPACE_ENCODED)); assertEquals("thumbsup%F0%9F%91%8Dthumbsup%F0%9F%91%8D", UriComponent.contextualEncode("thumbsup%F0%9F%91%8Dthumbsup\ud83d\udc4d", UriComponent.Type.QUERY)); assertEquals("thumbsup%F0%9F%91%8Dthumbsup%F0%9F%91%8D", UriComponent.contextualEncode("thumbsup%F0%9F%91%8Dthumbsup\ud83d\udc4d", UriComponent.Type.QUERY_PARAM)); }
@Test public void testContextualEncodeMatrixParam() { assertEquals("a%3Db%20c%3Bx", UriComponent.contextualEncode("a=b c;x", UriComponent.Type.MATRIX_PARAM)); assertEquals("a%3Db%20c%3Bx%3Dthumbsup%F0%9F%91%8D", UriComponent.contextualEncode("a=b c;x=thumbsup\ud83d\udc4d", UriComponent.Type.MATRIX_PARAM)); }
@Test public void testContextualEncodePercent() { assertEquals("%25", UriComponent.contextualEncode("%", UriComponent.Type.PATH)); assertEquals("a%25", UriComponent.contextualEncode("a%", UriComponent.Type.PATH)); assertEquals("a%25x", UriComponent.contextualEncode("a%x", UriComponent.Type.PATH)); assertEquals("a%25%20%20", UriComponent.contextualEncode("a% ", UriComponent.Type.PATH)); assertEquals("a%20a%20%20", UriComponent.contextualEncode("a a%20 ", UriComponent.Type.PATH)); }