View Javadoc
1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */ 2 package org.jmock.expectation; 3 4 abstract public class AbstractExpectation implements Verifiable, Expectation { 5 protected boolean myFailureModeIsImmediate = true; 6 protected String myName; 7 8 private boolean myHasExpectations = false; 9 10 public AbstractExpectation(String name) { 11 myName = name; 12 } 13 14 protected void assertEquals( 15 String msg, 16 int expectedValue, 17 int actualValue) { 18 assertEquals(msg, new Integer(expectedValue), new Integer(actualValue)); 19 } 20 21 /*** 22 * Due to junit Assert being a Singleton implemented with static methods, and java's 23 * unfortunate implementation of class methods (e.g. no late binding) it is 24 * necessary to re-implement this method here instead of over-riding failNotEquals 25 */ 26 27 protected void assertEquals( 28 String msg, 29 Object expectedValue, 30 Object actualValue) { 31 if (!myHasExpectations) 32 return; 33 34 if (expectedValue == null && actualValue == null) 35 return; 36 37 if (expectedValue != null && expectedValue.equals(actualValue)) 38 return; 39 40 junit.framework.Assert.fail( 41 myName 42 + " " 43 + msg 44 + "\nExpected: " 45 + expectedValue 46 + "\nReceived: " 47 + actualValue); 48 49 } 50 51 abstract public void clearActual(); 52 53 public boolean hasExpectations() { 54 return myHasExpectations; 55 } 56 57 public void setFailOnVerify() { 58 myFailureModeIsImmediate = false; 59 } 60 61 protected void setHasExpectations() { 62 clearActual(); 63 myHasExpectations = true; 64 } 65 66 protected boolean shouldCheckImmediately() { 67 return myFailureModeIsImmediate && myHasExpectations; 68 } 69 70 public abstract void verify(); 71 }

This page was automatically generated by Maven