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