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