1
2
3
4 package himock.core;
5
6 import java.lang.reflect.InvocationHandler;
7 import java.lang.reflect.Method;
8 import java.lang.reflect.Proxy;
9
10 /***
11 * @author Chen Peng ,chen56@msn.com
12 */
13 public class InterfaceMockObjectMaker implements IMockObjectMaker{
14 private final MockBehavior fMockInvocationer;
15 public InterfaceMockObjectMaker(MockBehavior mockInvocationer) {
16 this.fMockInvocationer=mockInvocationer;
17 }
18 public Object mock() {
19 return Proxy.newProxyInstance(this.getClass().getClassLoader(),
20 new Class[]{fMockInvocationer.fMockedType},
21 new InvocationHandlerImpl());
22 }
23 private class InvocationHandlerImpl implements InvocationHandler{
24
25
26
27 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
28 return fMockInvocationer.invoke(method, args);
29 }
30 }
31 }
32