1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.expectation;
3
4 import junit.framework.AssertionFailedError;
5 import org.jmock.AbstractTestCase;
6
7 public class TestExpectationValue extends AbstractTestCase {
8
9 private ExpectationValue myExpectation = new ExpectationValue("ExpectationValue for testing");
10
11 public void testBooleanFail() {
12 myExpectation.setExpected(true);
13
14 boolean testPasses = false;
15 try {
16 myExpectation.setActual(false);
17 } catch (AssertionFailedError ex) {
18 testPasses = true;
19 }
20
21 assertTrue("Should fail fast on boolean", testPasses);
22 }
23
24 public void testBooleanPass() {
25 myExpectation.setExpected(true);
26
27 myExpectation.setActual(true);
28
29 myExpectation.verify();
30 }
31
32 public void testExpectNothing() {
33 myExpectation.setExpectNothing();
34
35 assertTrue("Should have an expectation", myExpectation.hasExpectations());
36 }
37
38 public void testExpectNothingFail() {
39 myExpectation.setExpectNothing();
40
41 boolean testPasses = false;
42 try {
43 myExpectation.setActual("another object");
44 } catch (AssertionFailedError ex) {
45 testPasses = true;
46 }
47
48 assertTrue("Should fail fast on object", testPasses);
49 }
50
51 public void testFailOnVerify() {
52 myExpectation.setExpected("string object");
53 myExpectation.setFailOnVerify();
54
55 myExpectation.setActual("another object");
56 assertVerifyFails(myExpectation);
57 }
58
59 public void testFlushActual() {
60 myExpectation.setActual(10);
61
62 myExpectation.setExpectNothing();
63
64 myExpectation.verify();
65 }
66
67 public void testHasNoExpectations() {
68 myExpectation.setActual("a value");
69
70 assertTrue("Has no expectations", !myExpectation.hasExpectations());
71 }
72
73 public void testIntFail() {
74 myExpectation.setExpected(100);
75
76 boolean testPasses = false;
77 try {
78 myExpectation.setActual(150);
79 } catch (AssertionFailedError ex) {
80 testPasses = true;
81 }
82
83 assertTrue("Should fail fast on int", testPasses);
84 }
85
86 public void testIntPass() {
87 myExpectation.setExpected(100);
88
89 myExpectation.setActual(100);
90
91 myExpectation.verify();
92 }
93
94 public void testLongFail() {
95 myExpectation.setExpected(100L);
96
97 boolean testPasses = false;
98 try {
99 myExpectation.setActual(150L);
100 } catch (AssertionFailedError ex) {
101 testPasses = true;
102 }
103
104 assertTrue("Should fail fast on long", testPasses);
105 }
106
107 public void testLongPass() {
108 myExpectation.setExpected(100L);
109
110 myExpectation.setActual(100L);
111
112 myExpectation.verify();
113 }
114
115 public void testDoubleFail() {
116 myExpectation.setExpected(100.0);
117
118 boolean testPasses = false;
119 try {
120 myExpectation.setActual(150.0);
121 } catch (AssertionFailedError ex) {
122 testPasses = true;
123 }
124
125 assertTrue("Should fail fast on double", testPasses);
126 }
127
128 public void testDoublePass() {
129 myExpectation.setExpected(100.0);
130
131 myExpectation.setActual(100.0);
132
133 myExpectation.verify();
134 }
135
136 public void testNullFail() {
137 myExpectation.setExpected(null);
138
139 boolean testPasses = false;
140 try {
141 myExpectation.setActual("another object");
142 } catch (AssertionFailedError ex) {
143 testPasses = true;
144 }
145
146 assertTrue("Should fail fast on object", testPasses);
147 }
148
149 public void testNullPass() {
150 myExpectation.setExpected(null);
151 myExpectation.setActual(null);
152 myExpectation.verify();
153 }
154
155 public void testObject() {
156 myExpectation.setExpected("string object");
157
158 myExpectation.setActual("string object");
159
160 myExpectation.verify();
161 }
162
163 public void testObjectFail() {
164 myExpectation.setExpected("string object");
165
166 boolean testPasses = false;
167 try {
168 myExpectation.setActual("another object");
169 } catch (AssertionFailedError ex) {
170 testPasses = true;
171 }
172
173 assertTrue("Should fail fast on object", testPasses);
174 }
175 }
This page was automatically generated by Maven