Encoding { static CharSequence decode(final CharSequence s) { if (!contains(s, '%')) { return s.toString(); } return decode0(s); } private  Encoding();   }
@Test public void verifyDecode1OverlongFails() throws Exception { assertThat(decode(ONE_BYTE_ENCODED_OVERLONG2), is(nullValue())); }
@Test public void verifyDecode2Overlong3Fails() throws Exception { assertThat(decode(TWO_BYTES_ENCODED_OVERLONG3A), is(nullValue())); assertThat(decode(TWO_BYTES_ENCODED_OVERLONG3B), is(nullValue())); }
@Test public void verifyDecode2Overlong4Fails() throws Exception { assertThat(decode(TWO_BYTES_ENCODED_OVERLONG4), is(nullValue())); }
@Test public void verifyDecode3OverlongFails() throws Exception { assertThat(decode(THREE_BYTES_ENCODED_OVERLONG4), is(nullValue())); }
@Test public void verifyDecode4TooGreatFails() throws Exception { assertThat(decode(FOUR_BYTES_ENCODED_TOO_GREAT_F4), is(nullValue())); assertThat(decode(FOUR_BYTES_ENCODED_TOO_GREAT_F5), is(nullValue())); }
@Test public void verifyDecode2InvalidFails() throws Exception { assertThat(decode(TWO_BYTES_ENCODED_INVALID), is(nullValue())); assertThat(decode(TWO_BYTES_ENCODED_PERCENT_INVALID), is(nullValue())); }
@Test public void verifyDecode3InvalidFails() throws Exception { assertThat(decode(THREE_BYTES_ENCODED_INVALID1), is(nullValue())); assertThat(decode(THREE_BYTES_ENCODED_INVALID2), is(nullValue())); assertThat(decode(THREE_BYTES_ENCODED_A_PERCENT_INVALID), is(nullValue())); }
@Test public void verifyDecode4InvalidFails() throws Exception { assertThat(decode(FOUR_BYTES_ENCODED_INVALID1), is(nullValue())); assertThat(decode(FOUR_BYTES_ENCODED_INVALID2), is(nullValue())); assertThat(decode(FOUR_BYTES_ENCODED_INVALID3), is(nullValue())); assertThat(decode(FOUR_BYTES_ENCODED_PERCENT_INVALID), is(nullValue())); }
@Test public void testEntireUnicodeRange() throws UnsupportedEncodingException { for (int i = MIN_CODE_POINT; i < MAX_CODE_POINT; i++) { if (isSurrogate((char) i)) { continue; } final String s = String.valueOf(Character.toChars(i)); final String encoded = urlPathSegmentEscaper().escape(s); final CharSequence decoded = Encoding.decode(encoded); assertThat(decoded.toString(), is(s)); } }
@Test public void testDecode1() throws Exception { assertThat(decode(ONE_BYTE_ENCODED).toString(), is(ONE_BYTE)); assertThat(decode(ONE_BYTE_MIN_ENCODED).toString(), is(ONE_BYTE_MIN)); assertThat(decode(ONE_BYTE_MAX_ENCODED).toString(), is(ONE_BYTE_MAX)); }
@Test public void testDecode2() throws Exception { assertThat(decode(TWO_BYTES_ENCODED).toString(), is(TWO_BYTES)); assertThat(decode(TWO_BYTES_MIN_ENCODED).toString(), is(TWO_BYTES_MIN)); assertThat(decode(TWO_BYTES_MAX_ENCODED).toString(), is(TWO_BYTES_MAX)); }
@Test public void testDecode3() throws Exception { assertThat(decode(THREE_BYTES_ENCODED_A).toString(), is(THREE_BYTES_A)); assertThat(decode(THREE_BYTES_ENCODED_B).toString(), is(THREE_BYTES_B)); assertThat(decode(THREE_BYTES_MIN_ENCODED).toString(), is(THREE_BYTES_MIN)); assertThat(decode(THREE_BYTES_MAX_ENCODED).toString(), is(THREE_BYTES_MAX)); }
@Test public void testDecode4() throws Exception { assertThat(decode(FOUR_BYTES_ENCODED).toString(), is(FOUR_BYTES)); assertThat(decode(FOUR_BYTES_MAX_ENCODED).toString(), is(FOUR_BYTES_MAX)); }
@Test public void testDecodeMix() { final String expected = "mixed ascii with " + "1 byte sequences (" + ONE_BYTE + ") and " + "2 byte sequences (" + TWO_BYTES + ") and " + "3 byte sequences (" + THREE_BYTES_A + ") and " + "4 byte sequences (" + FOUR_BYTES + ")"; final String encoded = "mixed ascii with " + "1 byte sequences (" + ONE_BYTE_ENCODED + ") and " + "2 byte sequences (" + TWO_BYTES_ENCODED + ") and " + "3 byte sequences (" + THREE_BYTES_ENCODED_A + ") and " + "4 byte sequences (" + FOUR_BYTES_ENCODED + ")"; assertThat(String.valueOf(decode(encoded)), is(expected)); }