KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > mockobjects > TestExpectationValue


1 package test.mockobjects;
2
3 import junit.framework.*;
4 import com.mockobjects.*;
5 import com.mockobjects.util.*;
6
7 /**
8  * JUnit test case for TestExpectationValue
9  */

10
11 public class TestExpectationValue extends TestCaseMo {
12     private static final Class JavaDoc THIS = TestExpectationValue.class;
13
14     private ExpectationValue myExpectation = new ExpectationValue("ExpectationValue for testing");
15
16     public TestExpectationValue(String JavaDoc name) {
17         super(name);
18     }
19
20     public static void main(String JavaDoc[] args) {
21         start(new String JavaDoc[] { THIS.getName()});
22     }
23
24     public static Test suite() {
25         return new TestSuite(THIS);
26     }
27
28     public void testBooleanFail() {
29         myExpectation.setExpected(true);
30
31         boolean testPasses = false;
32         try {
33             myExpectation.setActual(false);
34         } catch (AssertionFailedError ex) {
35             testPasses = true;
36         }
37
38         assertTrue("Should fail fast on boolean", testPasses);
39     }
40
41     public void testBooleanPass() {
42         myExpectation.setExpected(true);
43
44         myExpectation.setActual(true);
45
46         myExpectation.verify();
47     }
48
49     public void testExpectNothing() {
50         myExpectation.setExpectNothing();
51
52         assertTrue("Should have an expectation", myExpectation.hasExpectations());
53     }
54
55     public void testExpectNothingFail() {
56         myExpectation.setExpectNothing();
57
58         boolean testPasses = false;
59         try {
60             myExpectation.setActual("another object");
61         } catch (AssertionFailedError ex) {
62             testPasses = true;
63         }
64
65         assertTrue("Should fail fast on object", testPasses);
66     }
67
68     public void testFailOnVerify() {
69         myExpectation.setExpected("string object");
70         myExpectation.setFailOnVerify();
71
72         myExpectation.setActual("another object");
73         assertVerifyFails(myExpectation);
74     }
75
76     public void testFlushActual() {
77         myExpectation.setActual(10);
78
79         myExpectation.setExpectNothing();
80
81         myExpectation.verify();
82     }
83
84     public void testHasNoExpectations() {
85         myExpectation.setActual("a value");
86
87         assertTrue("Has no expectations", !myExpectation.hasExpectations());
88     }
89
90     public void testIntFail() {
91         myExpectation.setExpected(100);
92
93         boolean testPasses = false;
94         try {
95             myExpectation.setActual(150);
96         } catch (AssertionFailedError ex) {
97             testPasses = true;
98         }
99
100         assertTrue("Should fail fast on int", testPasses);
101     }
102
103     public void testIntPass() {
104         myExpectation.setExpected(100);
105
106         myExpectation.setActual(100);
107
108         myExpectation.verify();
109     }
110
111     public void testLongFail() {
112         myExpectation.setExpected(100L);
113
114         boolean testPasses = false;
115         try {
116             myExpectation.setActual(150L);
117         } catch (AssertionFailedError ex) {
118             testPasses = true;
119         }
120
121         assertTrue("Should fail fast on long", testPasses);
122     }
123
124     public void testLongPass() {
125         myExpectation.setExpected(100L);
126
127         myExpectation.setActual(100L);
128
129         myExpectation.verify();
130     }
131
132     public void testDoubleFail() {
133         myExpectation.setExpected(100.0);
134
135         boolean testPasses = false;
136         try {
137             myExpectation.setActual(150.0);
138         } catch (AssertionFailedError ex) {
139             testPasses = true;
140         }
141
142         assertTrue("Should fail fast on double", testPasses);
143     }
144     
145     public void testDoublePass() {
146         myExpectation.setExpected(100.0);
147
148         myExpectation.setActual(100.0);
149
150         myExpectation.verify();
151     }
152
153     public void testNullFail() {
154         myExpectation.setExpected(null);
155
156         boolean testPasses = false;
157         try {
158             myExpectation.setActual("another object");
159         } catch (AssertionFailedError ex) {
160             testPasses = true;
161         }
162
163         assertTrue("Should fail fast on object", testPasses);
164     }
165
166     public void testNullPass() {
167         myExpectation.setExpected(null);
168         myExpectation.setActual(null);
169         myExpectation.verify();
170     }
171
172     public void testObject() {
173         myExpectation.setExpected("string object");
174
175         myExpectation.setActual("string object");
176
177         myExpectation.verify();
178     }
179
180     public void testObjectFail() {
181         myExpectation.setExpected("string object");
182
183         boolean testPasses = false;
184         try {
185             myExpectation.setActual("another object");
186         } catch (AssertionFailedError ex) {
187             testPasses = true;
188         }
189
190         assertTrue("Should fail fast on object", testPasses);
191     }
192 }
193
Popular Tags