1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.util;
17
18 import java.nio.ByteBuffer;
19 import java.nio.charset.CharacterCodingException;
20
21 import junit.framework.TestCase;
22
23 public class UriEncoderTest extends TestCase {
24
25 public void testEncode() {
26 assertEquals("Acad%C3%A9mico", UriEncoder.encode("Académico"));
27 assertEquals("Check http://yaml.org/spec/1.1/#escaping%20in%20URI/", "[]",
28 UriEncoder.encode("[]"));
29 }
30
31 public void testDecode() throws CharacterCodingException {
32 ByteBuffer buff = ByteBuffer.allocate(10);
33 buff.put((byte) 0x34);
34 buff.put((byte) 0x35);
35 buff.flip();
36 assertEquals("45", UriEncoder.decode(buff));
37 }
38
39 public void testFailDecode() throws CharacterCodingException {
40 ByteBuffer buff = ByteBuffer.allocate(10);
41 buff.put((byte) 0x34);
42 buff.put((byte) 0xC1);
43 buff.flip();
44 try {
45 UriEncoder.decode(buff);
46 fail("Invalid UTF-8 must not be accepted.");
47 } catch (Exception e) {
48 assertEquals("Input length = 1", e.getMessage());
49 }
50 }
51 }