KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > mockobjects > dynamic > MockConstraintMatcher


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 JavaDoc[] arg0){
18         myMatchesParameter0Values.addExpected(arg0);
19     }
20
21     public boolean matches(Object JavaDoc[] arg0){
22         myMatchesCalls.inc();
23         myMatchesParameter0Values.addActual(arg0);
24         Object JavaDoc nextReturnValue = myActualMatchesReturnValues.getNext();
25         if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException JavaDoc)
26             throw (RuntimeException JavaDoc)((ExceptionalReturnValue)nextReturnValue).getException();
27         return ((Boolean JavaDoc) nextReturnValue).booleanValue();
28     }
29
30     public void setupExceptionMatches(Throwable JavaDoc arg){
31         myActualMatchesReturnValues.add(new ExceptionalReturnValue(arg));
32     }
33
34     public void setupMatches(boolean arg){
35         myActualMatchesReturnValues.add(new Boolean JavaDoc(arg));
36     }
37
38     public void setExpectedGetConstraintsCalls(int calls){
39         myGetConstraintsCalls.setExpected(calls);
40     }
41
42     public Object JavaDoc[] getConstraints(){
43         myGetConstraintsCalls.inc();
44         Object JavaDoc nextReturnValue = myActualGetConstraintsReturnValues.getNext();
45         if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException JavaDoc)
46             throw (RuntimeException JavaDoc)((ExceptionalReturnValue)nextReturnValue).getException();
47         return (Object JavaDoc[]) nextReturnValue;
48     }
49
50     public void setupExceptionGetConstraints(Throwable JavaDoc arg){
51         myActualGetConstraintsReturnValues.add(new ExceptionalReturnValue(arg));
52     }
53
54     public void setupGetConstraints(Object JavaDoc[] 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