1 package junit.framework;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5 import java.lang.reflect.Modifier;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 public abstract class TestCase extends Assert implements Test {
77
78
79
80 private String fName;
81
82
83
84
85
86 public TestCase() {
87 fName = null;
88 }
89
90
91
92
93 public TestCase(String name) {
94 fName = name;
95 }
96
97
98
99
100 public int countTestCases() {
101 return 1;
102 }
103
104
105
106
107
108
109 protected TestResult createResult() {
110 return new TestResult();
111 }
112
113
114
115
116
117
118
119 public TestResult run() {
120 TestResult result = createResult();
121 run(result);
122 return result;
123 }
124
125
126
127
128 public void run(TestResult result) {
129 result.run(this);
130 }
131
132
133
134
135
136
137 public void runBare() throws Throwable {
138 Throwable exception = null;
139 setUp();
140 try {
141 runTest();
142 } catch (Throwable running) {
143 exception = running;
144 } finally {
145 try {
146 tearDown();
147 } catch (Throwable tearingDown) {
148 if (exception == null) exception = tearingDown;
149 }
150 }
151 if (exception != null) throw exception;
152 }
153
154
155
156
157
158
159 protected void runTest() throws Throwable {
160 assertNotNull("TestCase.fName cannot be null", fName);
161 Method runMethod = null;
162 try {
163
164
165
166
167 runMethod = getClass().getMethod(fName, (Class[]) null);
168 } catch (NoSuchMethodException e) {
169 fail("Method \"" + fName + "\" not found");
170 }
171 if (!Modifier.isPublic(runMethod.getModifiers())) {
172 fail("Method \"" + fName + "\" should be public");
173 }
174
175 try {
176 runMethod.invoke(this);
177 } catch (InvocationTargetException e) {
178 e.fillInStackTrace();
179 throw e.getTargetException();
180 } catch (IllegalAccessException e) {
181 e.fillInStackTrace();
182 throw e;
183 }
184 }
185
186
187
188
189
190 @SuppressWarnings("deprecation")
191 public static void assertTrue(String message, boolean condition) {
192 Assert.assertTrue(message, condition);
193 }
194
195
196
197
198
199 @SuppressWarnings("deprecation")
200 public static void assertTrue(boolean condition) {
201 Assert.assertTrue(condition);
202 }
203
204
205
206
207
208 @SuppressWarnings("deprecation")
209 public static void assertFalse(String message, boolean condition) {
210 Assert.assertFalse(message, condition);
211 }
212
213
214
215
216
217 @SuppressWarnings("deprecation")
218 public static void assertFalse(boolean condition) {
219 Assert.assertFalse(condition);
220 }
221
222
223
224
225 @SuppressWarnings("deprecation")
226 public static void fail(String message) {
227 Assert.fail(message);
228 }
229
230
231
232
233 @SuppressWarnings("deprecation")
234 public static void fail() {
235 Assert.fail();
236 }
237
238
239
240
241
242 @SuppressWarnings("deprecation")
243 public static void assertEquals(String message, Object expected, Object actual) {
244 Assert.assertEquals(message, expected, actual);
245 }
246
247
248
249
250
251 @SuppressWarnings("deprecation")
252 public static void assertEquals(Object expected, Object actual) {
253 Assert.assertEquals(expected, actual);
254 }
255
256
257
258
259 @SuppressWarnings("deprecation")
260 public static void assertEquals(String message, String expected, String actual) {
261 Assert.assertEquals(message, expected, actual);
262 }
263
264
265
266
267 @SuppressWarnings("deprecation")
268 public static void assertEquals(String expected, String actual) {
269 Assert.assertEquals(expected, actual);
270 }
271
272
273
274
275
276
277 @SuppressWarnings("deprecation")
278 public static void assertEquals(String message, double expected, double actual, double delta) {
279 Assert.assertEquals(message, expected, actual, delta);
280 }
281
282
283
284
285
286 @SuppressWarnings("deprecation")
287 public static void assertEquals(double expected, double actual, double delta) {
288 Assert.assertEquals(expected, actual, delta);
289 }
290
291
292
293
294
295
296 @SuppressWarnings("deprecation")
297 public static void assertEquals(String message, float expected, float actual, float delta) {
298 Assert.assertEquals(message, expected, actual, delta);
299 }
300
301
302
303
304
305 @SuppressWarnings("deprecation")
306 public static void assertEquals(float expected, float actual, float delta) {
307 Assert.assertEquals(expected, actual, delta);
308 }
309
310
311
312
313
314 @SuppressWarnings("deprecation")
315 public static void assertEquals(String message, long expected, long actual) {
316 Assert.assertEquals(message, expected, actual);
317 }
318
319
320
321
322 @SuppressWarnings("deprecation")
323 public static void assertEquals(long expected, long actual) {
324 Assert.assertEquals(expected, actual);
325 }
326
327
328
329
330
331 @SuppressWarnings("deprecation")
332 public static void assertEquals(String message, boolean expected, boolean actual) {
333 Assert.assertEquals(message, expected, actual);
334 }
335
336
337
338
339 @SuppressWarnings("deprecation")
340 public static void assertEquals(boolean expected, boolean actual) {
341 Assert.assertEquals(expected, actual);
342 }
343
344
345
346
347
348 @SuppressWarnings("deprecation")
349 public static void assertEquals(String message, byte expected, byte actual) {
350 Assert.assertEquals(message, expected, actual);
351 }
352
353
354
355
356 @SuppressWarnings("deprecation")
357 public static void assertEquals(byte expected, byte actual) {
358 Assert.assertEquals(expected, actual);
359 }
360
361
362
363
364
365 @SuppressWarnings("deprecation")
366 public static void assertEquals(String message, char expected, char actual) {
367 Assert.assertEquals(message, expected, actual);
368 }
369
370
371
372
373 @SuppressWarnings("deprecation")
374 public static void assertEquals(char expected, char actual) {
375 Assert.assertEquals(expected, actual);
376 }
377
378
379
380
381
382 @SuppressWarnings("deprecation")
383 public static void assertEquals(String message, short expected, short actual) {
384 Assert.assertEquals(message, expected, actual);
385 }
386
387
388
389
390 @SuppressWarnings("deprecation")
391 public static void assertEquals(short expected, short actual) {
392 Assert.assertEquals(expected, actual);
393 }
394
395
396
397
398
399 @SuppressWarnings("deprecation")
400 public static void assertEquals(String message, int expected, int actual) {
401 Assert.assertEquals(message, expected, actual);
402 }
403
404
405
406
407 @SuppressWarnings("deprecation")
408 public static void assertEquals(int expected, int actual) {
409 Assert.assertEquals(expected, actual);
410 }
411
412
413
414
415 @SuppressWarnings("deprecation")
416 public static void assertNotNull(Object object) {
417 Assert.assertNotNull(object);
418 }
419
420
421
422
423
424 @SuppressWarnings("deprecation")
425 public static void assertNotNull(String message, Object object) {
426 Assert.assertNotNull(message, object);
427 }
428
429
430
431
432
433
434
435
436 @SuppressWarnings("deprecation")
437 public static void assertNull(Object object) {
438 Assert.assertNull(object);
439 }
440
441
442
443
444
445 @SuppressWarnings("deprecation")
446 public static void assertNull(String message, Object object) {
447 Assert.assertNull(message, object);
448 }
449
450
451
452
453
454 @SuppressWarnings("deprecation")
455 public static void assertSame(String message, Object expected, Object actual) {
456 Assert.assertSame(message, expected, actual);
457 }
458
459
460
461
462
463 @SuppressWarnings("deprecation")
464 public static void assertSame(Object expected, Object actual) {
465 Assert.assertSame(expected, actual);
466 }
467
468
469
470
471
472
473 @SuppressWarnings("deprecation")
474 public static void assertNotSame(String message, Object expected, Object actual) {
475 Assert.assertNotSame(message, expected, actual);
476 }
477
478
479
480
481
482 @SuppressWarnings("deprecation")
483 public static void assertNotSame(Object expected, Object actual) {
484 Assert.assertNotSame(expected, actual);
485 }
486
487 @SuppressWarnings("deprecation")
488 public static void failSame(String message) {
489 Assert.failSame(message);
490 }
491
492 @SuppressWarnings("deprecation")
493 public static void failNotSame(String message, Object expected, Object actual) {
494 Assert.failNotSame(message, expected, actual);
495 }
496
497 @SuppressWarnings("deprecation")
498 public static void failNotEquals(String message, Object expected, Object actual) {
499 Assert.failNotEquals(message, expected, actual);
500 }
501
502 @SuppressWarnings("deprecation")
503 public static String format(String message, Object expected, Object actual) {
504 return Assert.format(message, expected, actual);
505 }
506
507
508
509
510
511 protected void setUp() throws Exception {
512 }
513
514
515
516
517
518 protected void tearDown() throws Exception {
519 }
520
521
522
523
524 @Override
525 public String toString() {
526 return getName() + "(" + getClass().getName() + ")";
527 }
528
529
530
531
532
533
534 public String getName() {
535 return fName;
536 }
537
538
539
540
541
542
543 public void setName(String name) {
544 fName = name;
545 }
546 }