public void testNameOrValue() { checkNoEncode(NAME_OR_VALUE, ""); checkNoEncode(NAME_OR_VALUE, "sdf"); assertEquals("sdf%20hfdf", EncodeOrCheck.nameOrValue("sdf%20hfdf", false, "guj")); assertEquals("sdf%2520hfdf", EncodeOrCheck.nameOrValue("sdf%20hfdf", true, "guj")); checkEncoding(NAME_OR_VALUE, "abc def", "abc%20def"); final StringBuilder reservedEnc = new StringBuilder(); for (int i = 0; i < EncodeOrCheck.RESERVED.length(); i++) { EncodeOrCheck.toHex(EncodeOrCheck.RESERVED.charAt(i), reservedEnc); } checkEncoding(NAME_OR_VALUE, EncodeOrCheck.RESERVED, reservedEnc.toString()); }
public void testCheckForInvalidUriChars() { final String allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890{}"; EncodeOrCheck.checkForInvalidUriChars(allowed, -1, ""); EncodeOrCheck.checkForInvalidUriChars("aaaaa", -1, ""); EncodeOrCheck.checkForInvalidUriChars("\\\\\\", -1, ""); checkForInvalidCharFail("a:a"); checkForInvalidCharFail("a:1"); checkForInvalidCharFail("/a:"); checkForInvalidCharFail("a:"); checkForInvalidCharFail("/"); checkForInvalidCharFail(" "); checkForInvalidCharFail("\0"); checkForInvalidCharFail("abc{ }kg jj"); EncodeOrCheck.checkForInvalidUriChars("abc{ }kgjj", -1, "test"); }
void checkForInvalidCharFail(String uriPart) { try { EncodeOrCheck.checkForInvalidUriChars(uriPart, -1, ""); fail("\"" + uriPart + "\" contains an invalid char. The test must fail"); } catch (IllegalArgumentException e) { // wonderful } }
public void testSchemeCheck() { // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) EncodeOrCheck.scheme("f"); }
public void testEncodePathWithoutMatrix() { EncodeOrCheck.pathWithoutMatrix(""); EncodeOrCheck.pathWithoutMatrix("%20"); }