KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > coder > EncodedWordTest


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

36 package org.columba.ristretto.coder;
37
38 import java.nio.charset.Charset JavaDoc;
39
40 import junit.framework.TestCase;
41
42 public class EncodedWordTest extends TestCase {
43
44     /**
45      * Constructor for EncodedWordTest.
46      * @param arg0
47      */

48     public EncodedWordTest(String JavaDoc arg0) {
49         super(arg0);
50     }
51
52     public void testDecodeNone() {
53         String JavaDoc input = "This is a simple Test";
54
55         StringBuffer JavaDoc result = EncodedWord.decode(input);
56         assertTrue(result.toString().equals(input));
57     }
58
59     public void testDecodeSimple() {
60         String JavaDoc input = "This is a =?iso-8859-1?q?s=FCmple?= Test";
61
62         StringBuffer JavaDoc result = EncodedWord.decode(input);
63         assertTrue(result.toString().equals("This is a s\u00fcmple Test"));
64     }
65
66     public void testDecodeWhitespaceNone() {
67         String JavaDoc input = "=?ISO-8859-1?Q?a?==?ISO-8859-1?Q?b?=";
68
69         StringBuffer JavaDoc result = EncodedWord.decode(input);
70         assertTrue(result.toString().equals("ab"));
71     }
72
73     public void testDecodeWhitespaceMulti() {
74         String JavaDoc input = "=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=";
75
76         StringBuffer JavaDoc result = EncodedWord.decode(input);
77         assertTrue(result.toString().equals("ab"));
78     }
79
80     public void testDecodeSimpleWithWS() {
81         String JavaDoc input = "This is a =?iso-8859-1?q?s=FCmple_?=Test";
82
83         StringBuffer JavaDoc result = EncodedWord.decode(input);
84         assertTrue(result.toString().equals("This is a s\u00fcmple Test"));
85     }
86
87     public void testDecodeBase64() {
88         String JavaDoc input =
89             "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?==?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=";
90
91         StringBuffer JavaDoc result = EncodedWord.decode(input);
92         assertTrue(
93             result.toString().equals(
94                 "If you can read this you understand the example."));
95     }
96
97     public void testEncodeNone() {
98         String JavaDoc input = "This is a test";
99
100         StringBuffer JavaDoc result =
101             EncodedWord.encode(
102                 input,
103                 Charset.forName("ISO-8859-1"),
104                 EncodedWord.QUOTED_PRINTABLE);
105         assertTrue(result.toString().equals("This is a test"));
106     }
107
108     public void testEncodeSimple() {
109         String JavaDoc input = "This is a s\u00fcmple test";
110
111         StringBuffer JavaDoc result =
112             EncodedWord.encode(
113                 input,
114                 Charset.forName("ISO-8859-1"),
115                 EncodedWord.QUOTED_PRINTABLE);
116         assertTrue(
117             result.toString().equals(
118                 "This is a =?ISO-8859-1?q?s=FCmple_?=test"));
119     }
120
121     public void testEncodeCombined() {
122         String JavaDoc input = "This is a s\u00fcmple s\u00fcmple test";
123
124         StringBuffer JavaDoc result =
125             EncodedWord.encode(
126                 input,
127                 Charset.forName("ISO-8859-1"),
128                 EncodedWord.QUOTED_PRINTABLE);
129         assertTrue(
130             result.toString().equals(
131                 "This is a =?ISO-8859-1?q?s=FCmple_s=FCmple_?=test"));
132     }
133
134     public void testEncodeSimpleBase64() {
135         String JavaDoc input = "This is a s\u00fcmple test";
136
137         StringBuffer JavaDoc result =
138             EncodedWord.encode(
139                 input,
140                 Charset.forName("ISO-8859-1"),
141                 EncodedWord.BASE64);
142         assertTrue(
143             result.toString().equals(
144                 "This is a =?ISO-8859-1?b?c/xtcGxlIA==?=test"));
145     }
146
147     public void testEncodeBase64EOF() {
148         String JavaDoc input = "This is a s\u00fcmple ";
149
150         StringBuffer JavaDoc result =
151             EncodedWord.encode(
152                 input,
153                 Charset.forName("ISO-8859-1"),
154                 EncodedWord.BASE64);
155         assertTrue(
156             result.toString().equals(
157                 "This is a =?ISO-8859-1?b?c/xtcGxlIA==?="));
158     }
159
160
161     public void testEncodelong() {
162         String JavaDoc input =
163             "This is a s\u00fcmplebutmegalongencodedwordsothatthesecondencodedwordmustbe s\u00fcmple test";
164
165         StringBuffer JavaDoc result =
166             EncodedWord.encode(
167                 input,
168                 Charset.forName("ISO-8859-1"),
169                 EncodedWord.QUOTED_PRINTABLE);
170         assertTrue(
171             result.toString().equals(
172                 "This is a =?ISO-8859-1?q?s=FCmplebutmegalongencodedwordsothatthesecondencodedwordmustbe_?==?ISO-8859-1?q?s=FCmple_?=test"));
173     }
174     
175
176
177 }
178
Popular Tags