KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > StringAssertTest


1 package junitx.framework;
2
3 import junit.framework.AssertionFailedError;
4 import junit.framework.TestCase;
5
6 /**
7  * @version $Revision: 1.3 $ $Date: 2003/04/09 04:39:40 $
8  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
9  */

10 public class StringAssertTest
11         extends TestCase {
12
13     public StringAssertTest(String JavaDoc name) {
14         super(name);
15     }
16
17     public void testSuccessContains() {
18         StringAssert.assertContains("is a", "This is a message");
19     }
20
21     public void testFailNullExpectedContains() {
22         try {
23             StringAssert.assertContains(null, "This is a message");
24         } catch (AssertionFailedError e) {
25             return;
26         }
27         fail("Should have thrown exception");
28     }
29
30     public void testFailNullActualContains() {
31         try {
32             StringAssert.assertContains("is another", null);
33         } catch (AssertionFailedError e) {
34             return;
35         }
36         fail("Should have thrown exception");
37     }
38
39     public void testFailNullBothContains() {
40         try {
41             StringAssert.assertContains(null, null);
42         } catch (AssertionFailedError e) {
43             return;
44         }
45         fail("Should have thrown exception");
46     }
47
48     public void testFailContains() {
49         try {
50             StringAssert.assertContains("is another", "This is a message");
51         } catch (AssertionFailedError e) {
52             return;
53         }
54         fail("Should have thrown exception");
55     }
56
57     public void testSuccessNotContains() {
58         StringAssert.assertNotContains("is another", "This is a message");
59     }
60
61     public void testSuccessNullActualNotContains() {
62         StringAssert.assertNotContains("is another", null);
63     }
64
65     public void testSuccessNullExpectedNotContains() {
66         StringAssert.assertNotContains(null, "This is a message");
67     }
68
69     public void testFailureNullBothNotContains() {
70         try {
71             StringAssert.assertNotContains(null, null);
72         } catch (AssertionFailedError e) {
73             return;
74         }
75         fail("Should have thrown exception");
76     }
77
78     public void testFailNotContains() {
79         try {
80             StringAssert.assertNotContains("is a", "This is a message");
81         } catch (AssertionFailedError e) {
82             return;
83         }
84         fail("Should have thrown exception");
85     }
86
87     // tests for startsWith
88

89     public void testSuccessStartsWith() {
90         StringAssert.assertStartsWith("This is a", "This is a message");
91     }
92
93     public void testFailNullExpectedStartsWith() {
94         try {
95             StringAssert.assertStartsWith(null, "This is a message");
96         } catch (AssertionFailedError e) {
97             return;
98         }
99         fail("Should have thrown exception");
100     }
101
102     public void testFailNullActualStartsWith() {
103         try {
104             StringAssert.assertStartsWith("is another", null);
105         } catch (AssertionFailedError e) {
106             return;
107         }
108         fail("Should have thrown exception");
109     }
110
111     public void testFailNullBothStartsWith() {
112         try {
113             StringAssert.assertStartsWith(null, null);
114         } catch (AssertionFailedError e) {
115             return;
116         }
117         fail("Should have thrown exception");
118     }
119
120     public void testFailStartsWith() {
121         try {
122             StringAssert.assertStartsWith("is another", "This is a message");
123         } catch (AssertionFailedError e) {
124             return;
125         }
126         fail("Should have thrown exception");
127     }
128
129     public void testSuccessNotStartsWith() {
130         StringAssert.assertNotStartsWith("is another", "This is a message");
131     }
132
133     public void testSuccessNullActualNotStartsWith() {
134         StringAssert.assertNotStartsWith("is another", null);
135     }
136
137     public void testSuccessNullExpectedNotStartsWith() {
138         StringAssert.assertNotStartsWith(null, "This is a message");
139     }
140
141     public void testFailureNullBothNotStartsWith() {
142         try {
143             StringAssert.assertNotStartsWith(null, null);
144         } catch (AssertionFailedError e) {
145             return;
146         }
147         fail("Should have thrown exception");
148     }
149
150     public void testFailNotStartsWith() {
151         try {
152             StringAssert.assertNotStartsWith("This is a", "This is a message");
153         } catch (AssertionFailedError e) {
154             return;
155         }
156         fail("Should have thrown exception");
157     }
158     
159     // tests for EndsWith
160

161     public void testSuccessEndsWith() {
162         StringAssert.assertEndsWith("a message", "This is a message");
163     }
164
165     public void testFailNullExpectedEndsWith() {
166         try {
167             StringAssert.assertEndsWith(null, "This is a message");
168         } catch (AssertionFailedError e) {
169             return;
170         }
171         fail("Should have thrown exception");
172     }
173
174     public void testFailNullActualEndsWith() {
175         try {
176             StringAssert.assertEndsWith("is another", null);
177         } catch (AssertionFailedError e) {
178             return;
179         }
180         fail("Should have thrown exception");
181     }
182
183     public void testFailNullBothEndsWith() {
184         try {
185             StringAssert.assertEndsWith(null, null);
186         } catch (AssertionFailedError e) {
187             return;
188         }
189         fail("Should have thrown exception");
190     }
191
192     public void testFailEndsWith() {
193         try {
194             StringAssert.assertEndsWith("another message", "This is a message");
195         } catch (AssertionFailedError e) {
196             return;
197         }
198         fail("Should have thrown exception");
199     }
200
201     public void testSuccessNotEndsWith() {
202         StringAssert.assertNotEndsWith("another message", "This is a message");
203     }
204
205     public void testSuccessNullActualNotEndsWith() {
206         StringAssert.assertNotEndsWith("is another", null);
207     }
208
209     public void testSuccessNullExpectedNotEndsWith() {
210         StringAssert.assertNotEndsWith(null, "This is a message");
211     }
212
213     public void testFailureNullBothNotEndsWith() {
214         try {
215             StringAssert.assertNotEndsWith(null, null);
216         } catch (AssertionFailedError e) {
217             return;
218         }
219         fail("Should have thrown exception");
220     }
221
222     public void testFailNotEndsWith() {
223         try {
224             StringAssert.assertNotEndsWith("a message", "This is a message");
225         } catch (AssertionFailedError e) {
226             return;
227         }
228         fail("Should have thrown exception");
229     }
230     
231 }
232
Popular Tags