1 3 package test.jmock.core.testsupport; 4 5 import junit.framework.Assert; 6 import org.jmock.core.Constraint; 7 import org.jmock.core.Verifiable; 8 9 10 public class MockConstraint extends Assert implements Constraint, Verifiable 11 { 12 private String description; 13 private Object expectedArg; 14 private boolean result; 15 private boolean wasChecked = false; 16 17 18 public MockConstraint( String description ) { 19 this(description, null, true); 20 wasChecked = true; 21 } 22 23 public MockConstraint( String description, Object expectedArg, boolean result ) { 24 this.description = description; 25 this.expectedArg = expectedArg; 26 this.result = result; 27 } 28 29 public StringBuffer describeTo( StringBuffer buffer ) { 30 return buffer.append(description); 31 } 32 33 public boolean eval( Object arg ) { 34 assertSame("Should be expected argument", expectedArg, arg); 35 wasChecked = true; 36 return result; 37 } 38 39 public void verify() { 40 assertTrue(description + " should have been checked", wasChecked); 41 } 42 } 43 | Popular Tags |