KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > cglib > CGLIBCoreMock


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

3 package org.jmock.cglib;
4
5 import java.lang.reflect.Method JavaDoc;
6 import net.sf.cglib.proxy.Enhancer;
7 import net.sf.cglib.proxy.MethodInterceptor;
8 import net.sf.cglib.proxy.MethodProxy;
9 import org.jmock.core.AbstractDynamicMock;
10 import org.jmock.core.Invocation;
11 import org.jmock.core.InvocationDispatcher;
12 import org.jmock.core.LIFOInvocationDispatcher;
13
14
15 public class CGLIBCoreMock
16         extends AbstractDynamicMock
17         implements MethodInterceptor
18 {
19     private Object JavaDoc proxy;
20
21     public CGLIBCoreMock( Class JavaDoc mockedType ) {
22         this(mockedType,
23              mockNameFromClass(mockedType),
24              new LIFOInvocationDispatcher());
25     }
26
27     public CGLIBCoreMock( Class JavaDoc mockedType, String JavaDoc name ) {
28         this(mockedType, name, new LIFOInvocationDispatcher());
29     }
30
31     public CGLIBCoreMock( Class JavaDoc mockedType,
32                           String JavaDoc name,
33                           InvocationDispatcher invocationDispatcher ) {
34         super(mockedType, name, invocationDispatcher);
35         this.proxy = Enhancer.create(mockedType, this);
36     }
37
38     public Object JavaDoc proxy() {
39         return this.proxy;
40     }
41
42     public Object JavaDoc intercept( Object JavaDoc thisProxy, Method JavaDoc method, Object JavaDoc[] args,
43                              MethodProxy superProxy )
44             throws Throwable JavaDoc {
45         Invocation invocation = new Invocation(proxy, method, args);
46         return mockInvocation(invocation);
47     }
48 }
49
Popular Tags