1 3 package org.jmock.expectation; 4 5 import org.jmock.core.Verifiable; 6 7 8 abstract public class AbstractExpectation implements Verifiable, Expectation 9 { 10 protected boolean myFailureModeIsImmediate = true; 11 protected String myName; 12 13 private boolean myHasExpectations = false; 14 15 public AbstractExpectation( String name ) { 16 myName = name; 17 } 18 19 protected void assertEquals( String msg, 20 int expectedValue, 21 int actualValue ) { 22 assertEquals(msg, new Integer (expectedValue), new Integer (actualValue)); 23 } 24 25 30 31 protected void assertEquals( String msg, 32 Object expectedValue, 33 Object actualValue ) { 34 if (!myHasExpectations) { 35 return; 36 } 37 38 if (expectedValue == null && actualValue == null) { 39 return; 40 } 41 42 if (expectedValue != null && expectedValue.equals(actualValue)) { 43 return; 44 } 45 46 junit.framework.Assert.fail(myName 47 + " " 48 + msg 49 + "\nExpected: " 50 + expectedValue 51 + "\nReceived: " 52 + actualValue); 53 54 } 55 56 abstract public void clearActual(); 57 58 public boolean hasExpectations() { 59 return myHasExpectations; 60 } 61 62 public void setFailOnVerify() { 63 myFailureModeIsImmediate = false; 64 } 65 66 protected void setHasExpectations() { 67 clearActual(); 68 myHasExpectations = true; 69 } 70 71 protected boolean shouldCheckImmediately() { 72 return myFailureModeIsImmediate && myHasExpectations; 73 } 74 75 public abstract void verify(); 76 } 77
| Popular Tags
|