KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > AssertTest


1 package junitx.framework;
2
3 import junit.framework.AssertionFailedError;
4 import junit.framework.TestCase;
5
6 /**
7  * @version $Revision: 1.6 $ $Date: 2003/02/10 20:26:42 $
8  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir Bossicard</a>
9  */

10 public class AssertTest
11         extends TestCase {
12
13     public AssertTest(String JavaDoc name) {
14         super(name);
15     }
16
17     public void testSuccessAssertFalse() {
18         Assert.assertFalse(false);
19     }
20
21     public void testFailAssertFalse()
22             throws Exception JavaDoc {
23         try {
24             Assert.assertFalse(true);
25         } catch (AssertionFailedError e) {
26             return;
27         }
28         fail("Should have thrown exception");
29     }
30
31     public void testSucceedAssertNotEquals()
32             throws Exception JavaDoc {
33         Assert.assertNotEquals(new Integer JavaDoc(1), new Integer JavaDoc(2));
34     }
35
36     public void testSucceedAssertNotEqualsNullExpected()
37             throws Exception JavaDoc {
38         Assert.assertNotEquals(null, new Integer JavaDoc(2));
39     }
40
41     public void testSucceedAssertNotEqualsNullActual()
42             throws Exception JavaDoc {
43         Assert.assertNotEquals(new Integer JavaDoc(1), null);
44     }
45
46     public void testFailAssertNotEquals()
47             throws Exception JavaDoc {
48         try {
49             Assert.assertNotEquals(new Integer JavaDoc(2), new Integer JavaDoc(2));
50         } catch (AssertionFailedError e) {
51             return;
52         }
53         fail("Should have thrown exception");
54     }
55
56     public void testFailAssertNotEqualsNulls()
57             throws Exception JavaDoc {
58         try {
59             Assert.assertNotEquals(null, null);
60         } catch (AssertionFailedError e) {
61             return;
62         }
63         fail("Should have thrown exception");
64     }
65
66     public void testSucceedAssertNotEqualsFloat() {
67         Assert.assertNotEquals(1.0d, 2.0d, 0.5d);
68     }
69
70     public void testFailAssertNotEqualsFloat() {
71         try {
72             Assert.assertNotEquals(1.0d, 1.5d, 1.0d);
73         } catch (AssertionFailedError e) {
74             return;
75         }
76         fail("Should have thrown exception");
77     }
78
79     public void testSucceedNotSame() {
80         Assert.assertNotSame(new Integer JavaDoc(1), new Integer JavaDoc(1));
81     }
82
83     public void testFailNotSame() {
84         try {
85             Integer JavaDoc integer = new Integer JavaDoc(1);
86             Assert.assertNotSame(integer, integer);
87         } catch (AssertionFailedError e) {
88             return;
89         }
90         fail("Should have thrown exception");
91     }
92
93     public void testFailThrowable() {
94         try {
95             Assert.fail(new NullPointerException JavaDoc("dummy"));
96         } catch (AssertionFailedError e) {
97             return;
98         }
99         fail("Should have thrown exception");
100     }
101
102 }
103
Popular Tags