01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16:
17: package org.columba.mail.main;
18:
19: import java.util.Map;
20:
21: import junit.framework.TestCase;
22:
23: public class MessageOptionParserTest extends TestCase {
24:
25: public void testSingle() {
26: String input = "to=test@star.de";
27: Map result = MessageOptionParser.parse(input);
28:
29: assertEquals(1, result.keySet().size());
30: assertEquals(result.get("to"), "test@star.de");
31: }
32:
33: public void testSingleQuoted() {
34: String input = "\"to=test@star.de\"";
35: Map result = MessageOptionParser.parse(input);
36:
37: assertEquals(1, result.keySet().size());
38: assertEquals(result.get("to"), "test@star.de");
39: }
40:
41: public void testSingleEscaped() {
42: String input = "subject=\\'High\\' comma!";
43: Map result = MessageOptionParser.parse(input);
44:
45: assertEquals(1, result.keySet().size());
46: assertEquals(result.get("subject"), "'High' comma!");
47: }
48:
49: public void testMultiple() {
50: String input = "to=test@star.de,subject=this is amazing!";
51: Map result = MessageOptionParser.parse(input);
52:
53: assertEquals(2, result.keySet().size());
54: assertEquals("test@star.de", result.get("to"));
55: assertEquals("this is amazing!", result.get("subject"));
56: }
57:
58: public void testSingleWithMultiValue() {
59: String input = "to='test@star.de,toast@star.de'";
60: Map result = MessageOptionParser.parse(input);
61:
62: assertEquals(1, result.keySet().size());
63: assertEquals(2, ((String[]) result.get("to")).length);
64: assertEquals("test@star.de", ((String[]) result.get("to"))[0]);
65: assertEquals("toast@star.de", ((String[]) result.get("to"))[1]);
66: }
67:
68: public void testMultipleWithMultiValue() {
69: String input = "to='test@star.de,toast@star.de',from='test@star.de,toast@star.de'";
70: Map result = MessageOptionParser.parse(input);
71:
72: assertEquals(2, result.keySet().size());
73: assertEquals(2, ((String[]) result.get("to")).length);
74: assertEquals("test@star.de", ((String[]) result.get("to"))[0]);
75: assertEquals("toast@star.de", ((String[]) result.get("to"))[1]);
76:
77: assertEquals(2, ((String[]) result.get("from")).length);
78: assertEquals("test@star.de", ((String[]) result.get("from"))[0]);
79: assertEquals("toast@star.de",
80: ((String[]) result.get("from"))[1]);
81: }
82:
83: public void testMultipleMixed() {
84: String input = "to='test@star.de,toast@star.de',subject=Hello World!,from='test@star.de,toast@star.de'";
85: Map result = MessageOptionParser.parse(input);
86:
87: assertEquals(3, result.keySet().size());
88: assertEquals(2, ((String[]) result.get("to")).length);
89: assertEquals("test@star.de", ((String[]) result.get("to"))[0]);
90: assertEquals("toast@star.de", ((String[]) result.get("to"))[1]);
91:
92: assertEquals(2, ((String[]) result.get("from")).length);
93: assertEquals("test@star.de", ((String[]) result.get("from"))[0]);
94: assertEquals("toast@star.de",
95: ((String[]) result.get("from"))[1]);
96:
97: assertEquals("Hello World!", result.get("subject"));
98: }
99: }
|