KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > builder > testsupport > MockStubMatchersCollection


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.builder.testsupport;
4
5 import junit.framework.Assert;
6 import org.jmock.core.InvocationMatcher;
7 import org.jmock.core.Stub;
8 import org.jmock.core.StubMatchersCollection;
9 import org.jmock.expectation.ExpectationValue;
10 import org.jmock.util.Verifier;
11
12
13 public class MockStubMatchersCollection implements StubMatchersCollection
14 {
15     public ExpectationValue addedMatcher = new ExpectationValue("added matcher");
16     public ExpectationValue addedMatcherType = new ExpectationValue("added matcher type");
17
18     public void addMatcher( InvocationMatcher matcher ) {
19         addedMatcher.setActual(matcher);
20         addedMatcherType.setActual(matcher.getClass());
21     }
22
23     public ExpectationValue setStubType = new ExpectationValue("set stub type");
24     public ExpectationValue setStub = new ExpectationValue("set stub");
25     public ExpectationValue setStubReturnValue = new ExpectationValue("set stub return value");
26
27     public void setStub( Stub stub ) {
28         setStub.setActual(stub);
29         setStubType.setActual(stub.getClass());
30
31         if (setStubReturnValue.hasExpectations()) {
32             try {
33                 setStubReturnValue.setActual(stub.invoke(null));
34             }
35             catch (Throwable JavaDoc t) {
36                 Assert.fail("unexpected throw from stub: " + t);
37             }
38         }
39     }
40
41     public ExpectationValue setName = new ExpectationValue("setName name");
42
43     public void setName( String JavaDoc name ) {
44         setName.setActual(name);
45     }
46
47     public void verifyExpectations() {
48         Verifier.verifyObject(this);
49     }
50 }
51
Popular Tags