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