KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > expectation > ExpectationDoubleValueTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.expectation;
4
5 import junit.framework.AssertionFailedError;
6 import junit.framework.TestCase;
7 import org.jmock.expectation.AssertMo;
8 import org.jmock.expectation.ExpectationDoubleValue;
9
10
11 public class ExpectationDoubleValueTest extends TestCase
12 {
13
14     private ExpectationDoubleValue myExpectation =
15             new ExpectationDoubleValue("ExpectationDoubleValue for testing");
16
17     public void testExpectNothing() {
18         myExpectation.setExpectNothing();
19
20         assertTrue("Should have an expectation",
21                    myExpectation.hasExpectations());
22     }
23
24     public void testExpectNothingFail() {
25         myExpectation.setExpectNothing();
26
27         try {
28             myExpectation.setActual(100.0);
29             fail("Should fail fast");
30         }
31         catch (AssertionFailedError ex) {
32             // expected
33
}
34
35     }
36
37     public void testFailOnVerify() {
38         myExpectation.setExpected(0.0, 0.0);
39         myExpectation.setFailOnVerify();
40
41         myExpectation.setActual(1.0);
42         AssertMo.assertVerifyFails(myExpectation);
43     }
44
45     public void testFlushActual() {
46         myExpectation.setActual(10);
47
48         myExpectation.setExpectNothing();
49
50         myExpectation.verify();
51     }
52
53     public void testHasNoExpectations() {
54         myExpectation.setActual(0.0);
55
56         assertTrue("Has no expectations",
57                    !myExpectation.hasExpectations());
58     }
59
60     public void testFailOutsideError() {
61         myExpectation.setExpected(100.0, 1.0);
62
63         try {
64             myExpectation.setActual(102.0);
65             fail("Should fail fast on double");
66         }
67         catch (AssertionFailedError ex) {
68             //expected
69
}
70
71     }
72
73     public void testPassOnError() {
74         myExpectation.setExpected(100.0, 1.0);
75         myExpectation.setActual(101.0);
76         myExpectation.verify();
77     }
78
79     public void testPassWithinError() {
80         myExpectation.setExpected(100.0, 1.0);
81         myExpectation.setActual(100);
82         myExpectation.verify();
83     }
84 }
85
Popular Tags