1 package test.mockobjects; 2 3 import junit.framework.*; 4 import com.mockobjects.*; 5 import com.mockobjects.util.*; 6 7 10 11 public class TestExpectationCounter extends TestCaseMo { 12 private static final Class THIS = TestExpectationCounter.class; 13 14 public TestExpectationCounter(String name) { 15 super(name); 16 } 17 18 public static void main(String [] args) { 19 start(new String [] { THIS.getName()}); 20 } 21 22 public static Test suite() { 23 return new TestSuite(THIS); 24 } 25 26 public void testExpectNothing() { 27 ExpectationCounter e = new ExpectationCounter(""); 28 e.setExpectNothing(); 29 30 assertTrue("Has expectation", e.hasExpectations()); 31 e.verify(); 32 } 33 34 public void testExpectNothingFailure() { 35 ExpectationCounter e = new ExpectationCounter(""); 36 e.setExpectNothing(); 37 38 assertTrue("Has expectation", e.hasExpectations()); 39 try { 40 e.inc(); 41 } catch (AssertionFailedError ex) { 42 return; 43 } 44 fail("Should have failed immediately"); 45 } 46 47 public void testFailImmediately() { 48 ExpectationCounter aCounter = new ExpectationCounter("a test counter"); 49 aCounter.setExpected(1); 50 51 aCounter.inc(); 52 try { 53 aCounter.inc(); 54 } catch (AssertionFailedError ex) { 55 return; 56 } 57 fail("Should have failed immediately"); 58 } 59 60 public void testFailOnVerify() { 61 ExpectationCounter aCounter = new ExpectationCounter("a test counter"); 62 aCounter.setExpected(1); 63 aCounter.setFailOnVerify(); 64 65 aCounter.inc(); 66 aCounter.inc(); 67 68 assertVerifyFails(aCounter); 69 } 70 71 public void testFailure() { 72 ExpectationCounter e = new ExpectationCounter(""); 73 e.setExpected(1); 74 75 assertVerifyFails(e); 76 } 77 78 public void testFlushActual() { 79 ExpectationCounter e = new ExpectationCounter(""); 80 e.inc(); 81 82 e.setExpected(1); 83 e.inc(); 84 85 e.verify(); 86 } 87 88 public void testHasNoExpectations() { 89 ExpectationCounter aCounter = new ExpectationCounter("a test counter"); 90 91 aCounter.inc(); 92 assertTrue("Has no expectations", !aCounter.hasExpectations()); 93 } 94 95 public void testSuccess() { 96 ExpectationCounter e = new ExpectationCounter(""); 97 e.setExpected(1); 98 e.inc(); 99 100 e.verify(); 101 } 102 } 103 | Popular Tags |