1 package test.mockobjects.dynamic; 2 3 import com.mockobjects.*; 4 import com.mockobjects.dynamic.ConstraintMatcher; 5 6 public class MockConstraintMatcher implements ConstraintMatcher{ 7 private ExpectationCounter myMatchesCalls = new ExpectationCounter("MockConstraintMatcher.matches(Object[])"); 8 private ReturnValues myActualMatchesReturnValues = new ReturnValues("MockConstraintMatcher.matches(Object[])", true); 9 private ExpectationList myMatchesParameter0Values = new ExpectationList("MockConstraintMatcher.matches(Object[]) java.lang.Object"); 10 private ExpectationCounter myGetConstraintsCalls = new ExpectationCounter("MockConstraintMatcher.getConstraints()"); 11 private ReturnValues myActualGetConstraintsReturnValues = new ReturnValues("MockConstraintMatcher.getConstraints()", true); 12 13 public void setExpectedMatchesCalls(int calls){ 14 myMatchesCalls.setExpected(calls); 15 } 16 17 public void addExpectedMatches(Object [] arg0){ 18 myMatchesParameter0Values.addExpected(arg0); 19 } 20 21 public boolean matches(Object [] arg0){ 22 myMatchesCalls.inc(); 23 myMatchesParameter0Values.addActual(arg0); 24 Object nextReturnValue = myActualMatchesReturnValues.getNext(); 25 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 26 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 27 return ((Boolean ) nextReturnValue).booleanValue(); 28 } 29 30 public void setupExceptionMatches(Throwable arg){ 31 myActualMatchesReturnValues.add(new ExceptionalReturnValue(arg)); 32 } 33 34 public void setupMatches(boolean arg){ 35 myActualMatchesReturnValues.add(new Boolean (arg)); 36 } 37 38 public void setExpectedGetConstraintsCalls(int calls){ 39 myGetConstraintsCalls.setExpected(calls); 40 } 41 42 public Object [] getConstraints(){ 43 myGetConstraintsCalls.inc(); 44 Object nextReturnValue = myActualGetConstraintsReturnValues.getNext(); 45 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 46 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 47 return (Object []) nextReturnValue; 48 } 49 50 public void setupExceptionGetConstraints(Throwable arg){ 51 myActualGetConstraintsReturnValues.add(new ExceptionalReturnValue(arg)); 52 } 53 54 public void setupGetConstraints(Object [] arg){ 55 myActualGetConstraintsReturnValues.add(arg); 56 } 57 58 public void verify(){ 59 myMatchesCalls.verify(); 60 myMatchesParameter0Values.verify(); 61 myGetConstraintsCalls.verify(); 62 } 63 } 64 | Popular Tags |