KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > mockobjects > TestExpectationDoubleValue


1 package test.mockobjects;
2
3 import junit.framework.*;
4 import com.mockobjects.*;
5 import com.mockobjects.util.*;
6
7
8 public class TestExpectationDoubleValue extends TestCaseMo {
9     private static final Class JavaDoc THIS = TestExpectationDoubleValue.class;
10
11     private ExpectationDoubleValue myExpectation =
12         new ExpectationDoubleValue("ExpectationDoubleValue for testing");
13     
14     public TestExpectationDoubleValue(String JavaDoc name) {
15         super(name);
16     }
17     
18     public static void main(String JavaDoc[] args) {
19         start(new String JavaDoc[] { THIS.getName()});
20     }
21
22     public static Test suite() {
23         return new TestSuite(THIS);
24     }
25
26     public void testExpectNothing() {
27         myExpectation.setExpectNothing();
28
29         assertTrue("Should have an expectation",
30                    myExpectation.hasExpectations());
31     }
32
33     public void testExpectNothingFail() {
34         myExpectation.setExpectNothing();
35
36         try {
37             myExpectation.setActual(100.0);
38             fail("Should fail fast");
39         } catch (AssertionFailedError ex) {
40             // expected
41
}
42
43     }
44     
45     public void testFailOnVerify() {
46         myExpectation.setExpected( 0.0, 0.0 );
47         myExpectation.setFailOnVerify();
48
49         myExpectation.setActual(1.0);
50         assertVerifyFails(myExpectation);
51     }
52
53     public void testFlushActual() {
54         myExpectation.setActual(10);
55
56         myExpectation.setExpectNothing();
57
58         myExpectation.verify();
59     }
60     
61     public void testHasNoExpectations() {
62         myExpectation.setActual(0.0);
63
64         assertTrue( "Has no expectations",
65                     !myExpectation.hasExpectations());
66     }
67
68     public void testFailOutsideError() {
69         myExpectation.setExpected( 100.0, 1.0 );
70         
71         try {
72             myExpectation.setActual(102.0);
73             fail("Should fail fast on double");
74         } catch (AssertionFailedError ex) {
75             //expected
76
}
77
78     }
79     
80     public void testPassOnError() {
81         myExpectation.setExpected( 100.0, 1.0 );
82         myExpectation.setActual(101.0);
83         myExpectation.verify();
84     }
85
86     public void testPassWithinError() {
87         myExpectation.setExpected( 100.0, 1.0 );
88         myExpectation.setActual(100);
89         myExpectation.verify();
90     }
91 }
92
Popular Tags