KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > composer > SubjectTest


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.composer;
19
20 import junit.framework.TestCase;
21
22
23 /**
24  * Test cases for generating subject lines, when replying and/or forwarding
25  * messages
26  * <p>
27  *
28  * TODO: Re:[columba-devel]test-subject
29  *
30  * @author fdietz
31  */

32 public class SubjectTest extends TestCase {
33     /**
34  * Check if "Re: " is correctly prepended
35  *
36  */

37     public void testReply() {
38         String JavaDoc s = "Subject";
39
40         String JavaDoc result = MessageBuilderHelper.createReplySubject(s);
41
42         assertEquals("Re: Subject", result);
43     }
44
45     /**
46  * Check if "Fwd: " is correctly prepended
47  *
48  */

49     public void testForward() {
50         String JavaDoc s = "Subject";
51
52         String JavaDoc result = MessageBuilderHelper.createForwardSubject(s);
53
54         assertEquals("Fwd: Subject", result);
55     }
56
57     /**
58  * Check if "Re: " is only prepended if not already found in string
59  *
60  */

61     public void testReply2() {
62         String JavaDoc s = "Re: Subject";
63
64         String JavaDoc result = MessageBuilderHelper.createReplySubject(s);
65
66         assertEquals("Re: Subject", result);
67     }
68
69     /**
70  * Check if "Fwd: " is only prepended if not already found in string
71  *
72  */

73     public void testForward2() {
74         String JavaDoc s = "Fwd: Subject";
75
76         String JavaDoc result = MessageBuilderHelper.createForwardSubject(s);
77
78         assertEquals("Fwd: Subject", result);
79     }
80
81     /**
82  * Check if "Re:" is only prepended if not already found in string
83  * <p>
84  * Note, the missing space
85  */

86     public void testReply3() {
87         String JavaDoc s = "Re:Subject";
88
89         String JavaDoc result = MessageBuilderHelper.createReplySubject(s);
90
91         assertEquals("Re:Subject", result);
92     }
93
94     /**
95  * Check if "Fwd:" is only prepended if not already found in string
96  * <p>
97  * Note, the missing space
98  *
99  */

100     public void testForward3() {
101         String JavaDoc s = "Fwd:Subject";
102
103         String JavaDoc result = MessageBuilderHelper.createForwardSubject(s);
104
105         assertEquals("Fwd:Subject", result);
106     }
107
108     /**
109  * Test if string is matched correctly.
110  *
111  */

112     public void testAlreadyInString() {
113         String JavaDoc s = "Test: Hallo";
114
115         boolean result = MessageBuilderHelper.isAlreadyReply(s, "test:");
116
117         assertTrue(result);
118     }
119
120     /**
121  * Test for adding the "Re" when replying to mailing list messages.
122  */

123     public void testMailingListReplies() {
124         String JavaDoc s = "[columba.devel] a subject";
125         String JavaDoc result = MessageBuilderHelper.createReplySubject(s);
126         assertEquals("The \"Re:\" was not added to the subject",
127             "Re: [columba.devel] a subject", result);
128
129         s = "Re:[columba-devel]test-subject";
130         result = MessageBuilderHelper.createReplySubject(s);
131         assertEquals("The \"Re:\" was added to the subject",
132             "Re:[columba-devel]test-subject", result);
133
134         s = "[columba-devel] Re:] Test";
135         result = MessageBuilderHelper.createReplySubject(s);
136         assertEquals("The \"Re:\" was added to the subject",
137             "[columba-devel] Re:] Test", result);
138
139         s = "[columba-devel] Re: Re: re: Re: Test";
140         result = MessageBuilderHelper.createReplySubject(s);
141         assertEquals("The \"Re:\" was added to the subject",
142             "[columba-devel] Re: Re: re: Re: Test", result);
143     }
144
145     /**
146  * Test for adding the "fwd" when forwarding messages from a mailing list.
147  */

148     public void testMailingListForwards() {
149         String JavaDoc s = "[columba.devel] a subject";
150         String JavaDoc result = MessageBuilderHelper.createForwardSubject(s);
151         assertEquals("The \"Fwd:\" was not added to the subject",
152             "Fwd: [columba.devel] a subject", result);
153
154         s = "Fwd:[columba-devel]test-subject";
155         result = MessageBuilderHelper.createForwardSubject(s);
156         assertEquals("The \"Fwd:\" was added to the subject",
157             "Fwd:[columba-devel]test-subject", result);
158
159         s = "[columba-devel] Fwd:] Test";
160         result = MessageBuilderHelper.createForwardSubject(s);
161         assertEquals("The \"Fwd:\" was added to the subject",
162             "[columba-devel] Fwd:] Test", result);
163
164         s = "[columba-devel] Fwd: Re: re: Re: Test";
165         result = MessageBuilderHelper.createForwardSubject(s);
166         assertEquals("The \"Fwd:\" was added to the subject",
167             "[columba-devel] Fwd: Re: re: Re: Test", result);
168     }
169 }
170
Popular Tags