1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.beetstra.jutf7;
25
26 import java.nio.charset.Charset;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.Locale;
30
31 import junit.framework.TestCase;
32
33 public class CharsetProviderTest extends TestCase {
34 private CharsetProvider tested = new CharsetProvider();
35
36 public void testOK() throws Exception {
37 assertTrue(true);
38 }
39
40 public void testModifiedUTF7() throws Exception {
41 Charset charset = tested.charsetForName("x-modified-UTF-7");
42 assertNotNull("charset not found", charset);
43 assertEquals(ModifiedUTF7Charset.class, charset.getClass());
44 assertEquals(charset, tested.charsetForName("x-imap-modified-utf-7"));
45 assertEquals(charset, tested.charsetForName("x-imap4-modified-utf7"));
46 assertEquals(charset, tested.charsetForName("x-imap4-modified-utf-7"));
47 assertEquals(charset, tested.charsetForName("x-RFC3501"));
48 assertEquals(charset, tested.charsetForName("x-RFC-3501"));
49 }
50
51 public void testUTF7() throws Exception {
52 Charset charset = tested.charsetForName("UTF-7");
53 assertNotNull("charset not found", charset);
54 assertEquals(UTF7Charset.class, charset.getClass());
55 assertEquals(charset, tested.charsetForName("utf-7"));
56 assertEquals(charset, tested.charsetForName("UNICODE-1-1-UTF-7"));
57 assertEquals(charset, tested.charsetForName("csUnicode11UTF7"));
58 assertEquals(charset, tested.charsetForName("x-RFC2152"));
59 assertEquals(charset, tested.charsetForName("x-RFC-2152"));
60 }
61
62 public void testUTF7optional() throws Exception {
63 Charset charset = tested.charsetForName("X-UTF-7-OPTIONAL");
64 assertNotNull("charset not found", charset);
65 assertEquals(UTF7Charset.class, charset.getClass());
66 assertEquals(charset, tested.charsetForName("x-utf-7-optional"));
67 assertEquals(charset, tested.charsetForName("x-RFC2152-optional"));
68 assertEquals(charset, tested.charsetForName("x-RFC-2152-optional"));
69 }
70
71 public void testNotHere() throws Exception {
72 assertNull(tested.charsetForName("X-DOES-NOT-EXIST"));
73 }
74
75 public void testIterator() throws Exception {
76 Iterator iterator = tested.charsets();
77 HashSet found = new HashSet();
78 while (iterator.hasNext())
79 found.add(iterator.next());
80 assertEquals(3, found.size());
81 Charset charset1 = tested.charsetForName("x-IMAP4-modified-UTF7");
82 Charset charset2 = tested.charsetForName("UTF-7");
83 Charset charset3 = tested.charsetForName("X-UTF-7-OPTIONAL");
84 assertTrue(found.contains(charset1));
85 assertTrue(found.contains(charset2));
86 assertTrue(found.contains(charset3));
87 }
88
89 public void testTurkish() throws Exception {
90 Locale.setDefault(new Locale("tr", "TR"));
91 assertEquals(tested.charsetForName("UTF-7"), tested.charsetForName("unicode-1-1-utf-7"));
92 }
93 }