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