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 TestExpectationCounter extends AbstractTestCase { 8 9 public void testExpectNothing() { 10 ExpectationCounter e = new ExpectationCounter(""); 11 e.setExpectNothing(); 12 13 assertTrue("Has expectation", e.hasExpectations()); 14 e.verify(); 15 } 16 17 public void testExpectNothingFailure() { 18 ExpectationCounter e = new ExpectationCounter(""); 19 e.setExpectNothing(); 20 21 assertTrue("Has expectation", e.hasExpectations()); 22 try { 23 e.inc(); 24 } catch (AssertionFailedError ex) { 25 return; 26 } 27 fail("Should have failed immediately"); 28 } 29 30 public void testFailImmediately() { 31 ExpectationCounter aCounter = new ExpectationCounter("a test counter"); 32 aCounter.setExpected(1); 33 34 aCounter.inc(); 35 try { 36 aCounter.inc(); 37 } catch (AssertionFailedError ex) { 38 return; 39 } 40 fail("Should have failed immediately"); 41 } 42 43 public void testFailOnVerify() { 44 ExpectationCounter aCounter = new ExpectationCounter("a test counter"); 45 aCounter.setExpected(1); 46 aCounter.setFailOnVerify(); 47 48 aCounter.inc(); 49 aCounter.inc(); 50 51 assertVerifyFails(aCounter); 52 } 53 54 public void testFailure() { 55 ExpectationCounter e = new ExpectationCounter(""); 56 e.setExpected(1); 57 58 assertVerifyFails(e); 59 } 60 61 public void testFlushActual() { 62 ExpectationCounter e = new ExpectationCounter(""); 63 e.inc(); 64 65 e.setExpected(1); 66 e.inc(); 67 68 e.verify(); 69 } 70 71 public void testHasNoExpectations() { 72 ExpectationCounter aCounter = new ExpectationCounter("a test counter"); 73 74 aCounter.inc(); 75 assertTrue("Has no expectations", !aCounter.hasExpectations()); 76 } 77 78 public void testSuccess() { 79 ExpectationCounter e = new ExpectationCounter(""); 80 e.setExpected(1); 81 e.inc(); 82 83 e.verify(); 84 } 85 }

This page was automatically generated by Maven