KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > stub > CustomStub


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

3 package org.jmock.core.stub;
4
5 import org.jmock.core.Stub;
6
7
8 /**
9  * A partial implementation of the Stub interface that makes it convenient to implement
10  * application-specific stubs with inline anonymous classes:
11  * <pre>
12  * final String name = "NAME";
13  * final StringBuffer buffer = new StringBuffer();
14  * <p/>
15  * mock.expect("describeTo", C.args(C.same(buffer))), new CustomStub("appends name to buffer") {
16  * public Object invoke( Invocation invocation ) throws Throwable {
17  * return buffer.append(name);
18  * }
19  * } );
20  * </pre>
21  */

22 public abstract class CustomStub implements Stub
23 {
24     private String JavaDoc description;
25
26     public CustomStub( String JavaDoc description ) {
27         this.description = description;
28     }
29
30     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
31         return buffer.append(description);
32     }
33 }
34
Popular Tags