KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > parser > AddressParserTest


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.parser;
37
38 import junit.framework.TestCase;
39
40 import org.columba.ristretto.message.Address;
41
42 public class AddressParserTest extends TestCase {
43
44     public void testSingle1() {
45         String JavaDoc testString = "Peter ?lafton <xyt@zpt.de>";
46         
47         
48         Address address;
49         try {
50             address = AddressParser.parseAddress(testString);
51         } catch (ParserException e) {
52             assertTrue(false);
53             return;
54         }
55         
56         Address testAddress = new Address( "Peter ?lafton", "xyt@zpt.de");
57         
58         assertTrue( address.equals( testAddress ));
59         assertTrue( address.getDisplayName().equals("Peter ?lafton"));
60         assertTrue( address.toString().equals("\"Peter ?lafton\" <xyt@zpt.de>"));
61     }
62
63 /*
64     public void testGroup() {
65         String testString = "\"GMX Kundennummer #7743037\": ;";
66         
67         
68         Address[] addressList;
69         try {
70             addressList = AddressParser.parseMailboxList(testString);
71         } catch (ParserException e) {
72             assertTrue(false);
73             return;
74         }
75         
76         assertTrue( addressList[0].getDisplayName().equals("\"GMX Kundennummer #7743037\""));
77     }
78 */

79     
80     
81     public void testSingle2() {
82         String JavaDoc testString = "<xyt@zpt.de>";
83         
84         
85         Address[] addressList;
86         try {
87             addressList = AddressParser.parseMailboxList(testString);
88         } catch (ParserException e) {
89             assertTrue(false);
90             return;
91         }
92         
93         Address testAddress = new Address( "xyt@zpt.de");
94         
95         assertTrue( addressList.length == 1);
96         assertTrue( ((Address) addressList[0]).equals( testAddress ));
97         assertTrue( ((Address) addressList[0]).getDisplayName().equals(""));
98         assertEquals( addressList[0].getMailAddress(), "xyt@zpt.de");
99     }
100
101     public void testSingle3() {
102         String JavaDoc testString = "xyt@zpt.de";
103         
104         
105         Address[] addressList;
106         try {
107             addressList = AddressParser.parseMailboxList(testString);
108         } catch (ParserException e) {
109             assertTrue(false);
110             return;
111         }
112         
113         Address testAddress = new Address( "xyt@zpt.de");
114         
115         assertTrue( addressList.length == 1);
116         assertTrue( ((Address) addressList[0]).equals( testAddress ));
117         assertTrue( ((Address) addressList[0]).getDisplayName().equals(""));
118     }
119
120     public void testSingle4() {
121         String JavaDoc testString = "\"Peter ?lafton\" <xyt@zpt.de>";
122         
123         
124         Address[] addressList;
125         try {
126             addressList = AddressParser.parseMailboxList(testString);
127         } catch (ParserException e) {
128             assertTrue(false);
129             return;
130         }
131         
132         Address testAddress = new Address( "Peter ?lafton", "xyt@zpt.de");
133         
134         assertTrue( addressList.length == 1);
135         assertTrue( ((Address) addressList[0]).equals( testAddress ));
136         assertTrue( ((Address) addressList[0]).getDisplayName().equals("Peter ?lafton"));
137     }
138     
139     
140     public void testMultiple1() {
141         String JavaDoc testString = "Peter ?lafton <xyt@zpt.de>, xyt@zpt.de, <xyt@zpt.de>";
142         
143         Address[] addressList;
144         try {
145             addressList = AddressParser.parseMailboxList(testString);
146         } catch (ParserException e) {
147             assertTrue(false);
148             return;
149         }
150         
151         assertTrue( addressList.length == 3);
152         assertTrue( ((Address) addressList[0]).equals( new Address( "Peter ?lafton", "xyt@zpt.de") ));
153         assertTrue( ((Address) addressList[0]).getDisplayName().equals("Peter ?lafton"));
154         assertTrue( ((Address) addressList[1]).equals( new Address( "xyt@zpt.de") ));
155         assertTrue( ((Address) addressList[2]).equals( new Address( "xyt@zpt.de") ));
156     }
157     
158     public void testMultiple2() {
159         String JavaDoc testString = "hans, peter, lukas";
160         
161         Address[] addressList;
162         try {
163             addressList = AddressParser.parseMailboxList(testString);
164         } catch (ParserException e) {
165             assertTrue(false);
166             return;
167         }
168         
169         assertTrue( addressList.length == 3);
170         assertTrue( ((Address) addressList[0]).equals( new Address( "hans") ));
171         assertTrue( ((Address) addressList[1]).equals( new Address( "peter") ));
172         assertTrue( ((Address) addressList[2]).equals( new Address( "lukas") ));
173     }
174
175     
176     public void testMultipleQuoted1() {
177         String JavaDoc testString = "\"Rmazam, Peter\" <xyt@zpt.de>, \"Bkalbal, Olaf\" <zkn@opb.com>";
178         
179         
180         Address[] addressList;
181         try {
182             addressList = AddressParser.parseMailboxList(testString);
183         } catch (ParserException e) {
184             assertTrue(false);
185             return;
186         }
187         
188         assertTrue( addressList.length == 2);
189         assertTrue( ((Address) addressList[0]).equals( new Address( "Rmazam, Peter", "xyt@zpt.de") ));
190         assertTrue( ((Address) addressList[0]).getDisplayName().equals("Rmazam, Peter"));
191         assertTrue( ((Address) addressList[1]).equals( new Address( "Bkalbal, Olaf", "zkn@opb.com") ));
192         assertTrue( ((Address) addressList[1]).getDisplayName().equals("Bkalbal, Olaf"));
193     }
194     
195     public void testSingle5() {
196         String JavaDoc testString = "columba-devel-admin@lists.sourceforge.net";
197         
198         
199         Address[] addressList;
200         try {
201                 addressList = AddressParser.parseMailboxList(testString);
202         } catch (ParserException e) {
203             assertTrue(false);
204             return;
205         }
206         
207         Address testAddress = new Address( "columba-devel-admin@lists.sourceforge.net");
208         
209         assertTrue( addressList.length == 1);
210         assertTrue( ((Address) addressList[0]).equals( testAddress ));
211     }
212     
213     
214     
215     
216     public void testAddressToString1() {
217         Address testAddress = new Address( "Timo Stich", "tstich@users.sourceforge.net");
218         String JavaDoc addressString = testAddress.toString();
219         assertTrue( addressString.equals("\"Timo Stich\" <tstich@users.sourceforge.net>"));
220     }
221
222     public void testAddressToString2() {
223         Address testAddress = new Address( "tstich@users.sourceforge.net");
224         String JavaDoc addressString = testAddress.toString();
225         assertTrue( addressString.equals("tstich@users.sourceforge.net"));
226     }
227     
228     public void testSingle6() {
229         String JavaDoc testString = "=?ISO-8859-1?Q?J=F6rg_Tester?= <tester@test.de>";
230         
231         Address address;
232         try {
233             address = AddressParser.parseAddress(testString);
234         } catch (ParserException e) {
235             assertTrue(false);
236             return;
237         }
238         
239         Address testAddress = new Address( "=?ISO-8859-1?Q?J=F6rg_Tester?=", "tester@test.de");
240         
241         assertTrue( address.equals( testAddress ));
242     }
243
244     public void testSingle7() {
245         String JavaDoc testString = "\"info@spreadshirt.de\"<info@spreadshirt.de>";
246         
247         
248         Address[] addressList;
249         try {
250             addressList = AddressParser.parseMailboxList(testString);
251         } catch (ParserException e) {
252             assertTrue(false);
253             return;
254         }
255         
256         Address testAddress = new Address( "info@spreadshirt.de", "info@spreadshirt.de");
257         
258         assertTrue( addressList.length == 1);
259         assertTrue( ((Address) addressList[0]).equals( testAddress ));
260         assertTrue( ((Address) addressList[0]).getDisplayName().equals("info@spreadshirt.de"));
261         assertEquals( addressList[0].getMailAddress(), "info@spreadshirt.de");
262     }
263
264 }
265
Popular Tags