KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > CoreMock


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

3 package org.jmock.core;
4
5 import java.lang.reflect.InvocationHandler JavaDoc;
6 import java.lang.reflect.Method JavaDoc;
7 import java.lang.reflect.Proxy JavaDoc;
8
9
10 public class CoreMock
11     extends AbstractDynamicMock
12     implements InvocationHandler JavaDoc
13 {
14     private Object JavaDoc proxy;
15
16     public CoreMock( Class JavaDoc mockedType, String JavaDoc name ) {
17         this(mockedType, name, new LIFOInvocationDispatcher());
18     }
19
20     public CoreMock( Class JavaDoc mockedType,
21                      String JavaDoc name,
22                      InvocationDispatcher invocationDispatcher )
23     {
24         super(mockedType, name, invocationDispatcher);
25         this.proxy = Proxy.newProxyInstance(mockedType.getClassLoader(),
26                                             new Class JavaDoc[]{mockedType},
27                                             this);
28     }
29
30     public Object JavaDoc proxy() {
31         return this.proxy;
32     }
33
34     public Object JavaDoc invoke( Object JavaDoc invokedProxy, Method JavaDoc method, Object JavaDoc[] args )
35         throws Throwable JavaDoc
36     {
37         Invocation invocation = new Invocation(invokedProxy, method, args);
38         return mockInvocation(invocation);
39     }
40 }
41
Popular Tags