1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.fileupload.util.mime;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.io.UnsupportedEncodingException;
22
23 import org.apache.commons.fileupload.util.mime.MimeUtility;
24 import org.junit.Test;
25
26
27
28
29
30
31
32 public final class MimeUtilityTestCase {
33
34 @Test
35 public void noNeedToDecode() throws Exception {
36 assertEncoded("abc", "abc");
37 }
38
39 @Test
40 public void decodeUtf8QuotedPrintableEncoded() throws Exception {
41 assertEncoded(" hé! àèôu !!!", "=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=");
42 }
43
44 @Test
45 public void decodeUtf8Base64Encoded() throws Exception {
46 assertEncoded(" hé! àèôu !!!", "=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?=");
47 }
48
49 @Test
50 public void decodeIso88591Base64Encoded() throws Exception {
51 assertEncoded("If you can read this you understand the example.",
52 "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
53 }
54
55 @Test
56 public void decodeIso88591Base64EncodedWithWhiteSpace() throws Exception {
57 assertEncoded("If you can read this you understand the example.",
58 "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\t \r\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
59 }
60
61 private static void assertEncoded(String expected, String encoded) throws Exception {
62 assertEquals(expected, MimeUtility.decodeText(encoded));
63 }
64
65 @Test(expected=UnsupportedEncodingException.class)
66 public void decodeInvalidEncoding() throws Exception {
67 MimeUtility.decodeText("=?invalid?B?xyz-?=");
68 }
69 }