KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > testsupport > MockInvocationDispatcher


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

3 package test.jmock.core.testsupport;
4
5 import org.jmock.core.Invocation;
6 import org.jmock.core.InvocationDispatcher;
7 import org.jmock.core.Invokable;
8 import org.jmock.core.Stub;
9 import org.jmock.expectation.ExpectationCounter;
10 import org.jmock.expectation.ExpectationValue;
11
12
13 public class MockInvocationDispatcher
14         extends MockVerifiable
15         implements InvocationDispatcher
16 {
17     public ExpectationValue dispatchInvocation = new ExpectationValue("dispatchInvocation");
18     public Object JavaDoc dispatchResult;
19     public Throwable JavaDoc dispatchThrowable;
20     public ExpectationValue addInvokable = new ExpectationValue("addInvokable");
21     public ExpectationCounter clearCalls = new ExpectationCounter("clear calls");
22     public String JavaDoc writeToOutput = "MockInvocationDispatcher.describeTo output";
23     public ExpectationValue setDefaultStub = new ExpectationValue("setDefaultStub");
24
25
26     public void setDefaultStub( Stub newDefaultStub ) {
27         setDefaultStub.setActual(newDefaultStub);
28     }
29
30     public void add( Invokable invokable ) {
31         addInvokable.setActual(invokable);
32     }
33
34     public void clear() {
35         clearCalls.inc();
36     }
37
38     public Object JavaDoc dispatch( Invocation invocation ) throws Throwable JavaDoc {
39         dispatchInvocation.setActual(invocation);
40         if (null != dispatchThrowable) {
41             throw dispatchThrowable;
42         }
43         return dispatchResult;
44     }
45
46     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
47         return buffer.append(writeToOutput);
48     }
49 }
50
Popular Tags