KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > AssertTest


1 package junit.tests;
2
3 import junit.framework.*;
4
5 public class AssertTest extends TestCase {
6     public AssertTest(String JavaDoc name) {
7         super(name);
8     }
9     
10     /**
11      * Test for the special Double.NaN value.
12      */

13     public void testAssertEqualsNaNFails() {
14         try {
15             assertEquals(1.234, Double.NaN, 0.0);
16         } catch (AssertionFailedError e) {
17             return;
18         }
19         fail();
20     }
21
22     public void testAssertNaNEqualsFails() {
23         try {
24             assertEquals(Double.NaN, 1.234, 0.0);
25         } catch (AssertionFailedError e) {
26             return;
27         }
28         fail();
29     }
30
31     public void testAssertNaNEqualsNaNFails() {
32         try {
33             assertEquals(Double.NaN, Double.NaN, 0.0);
34         } catch (AssertionFailedError e) {
35             return;
36         }
37         fail();
38     }
39
40     public void testAssertPosInfinityNotEqualsNegInfinity() {
41         try {
42             assertEquals(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0);
43         } catch (AssertionFailedError e) {
44             return;
45         }
46         fail();
47     }
48
49     public void testAssertPosInfinityNotEquals() {
50         try {
51             assertEquals(Double.POSITIVE_INFINITY, 1.23, 0.0);
52         } catch (AssertionFailedError e) {
53             return;
54         }
55         fail();
56     }
57
58     public void testAssertPosInfinityEqualsInfinity() {
59         assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0);
60     }
61     
62     public void testAssertNegInfinityEqualsInfinity() {
63         assertEquals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0);
64     }
65
66     public void testAssertEquals() {
67         Object JavaDoc o= new Object JavaDoc();
68         assertEquals(o, o);
69     }
70     
71     public void testAssertEqualsNull() {
72         assertEquals(null, null);
73     }
74     
75     public void testAssertNull() {
76         assertNull(null);
77     }
78     
79     public void testAssertNullNotEqualsNull() {
80         try {
81             assertEquals(null, new Object JavaDoc());
82         } catch (AssertionFailedError e) {
83             return;
84         }
85         fail();
86     }
87     
88     public void testAssertSame() {
89         Object JavaDoc o= new Object JavaDoc();
90         assertSame(o, o);
91     }
92     
93     public void testAssertSameFails() {
94         try {
95             assertSame(new Integer JavaDoc(1), new Integer JavaDoc(1));
96         } catch (AssertionFailedError e) {
97             return;
98         }
99         fail();
100     }
101
102     public void testFail() {
103         try {
104             fail();
105         } catch (AssertionFailedError e) {
106             return;
107         }
108         throw new AssertionFailedError(); // You can't call fail() here
109
}
110     
111     public void testFailAssertNotNull() {
112         try {
113             assertNotNull(null);
114         } catch (AssertionFailedError e) {
115             return;
116         }
117         fail();
118     }
119     
120     public void testSucceedAssertNotNull() {
121         assertNotNull(new Object JavaDoc());
122     }
123 }
Popular Tags