|
1 |
| package com.agical.rmock.extension.cglib; |
|
2 |
| |
|
3 |
| import java.lang.reflect.Method; |
|
4 |
| |
|
5 |
| import com.agical.rmock.core.InvocationHandler; |
|
6 |
| import com.agical.rmock.core.MethodHandle; |
|
7 |
| import com.agical.rmock.core.ProxyFactory; |
|
8 |
| import com.agical.rmock.core.expectation.ExpectationsState; |
|
9 |
| import com.agical.rmock.core.expectation.InvocationListener; |
|
10 |
| import com.agical.rmock.core.util.InterfaceMethodHandle; |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| class InterfaceInvocationHandler extends BaseInvocationHandler |
|
19 |
| implements net.sf.cglib.proxy.InvocationHandler { |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| private final InvocationHandler invocationHandler; |
|
24 |
| private final String id; |
|
25 |
| private final Class clazz; |
|
26 |
| private final ProxyFactory proxyFactory; |
|
27 |
| private Object proxy; |
|
28 |
| private final InvocationListener invocationListener; |
|
29 |
| private final ObjectReferenceRetriever objectReferenceRetriever; |
|
30 |
| private final ExpectationsState expectationsState; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
713
| public InterfaceInvocationHandler(InvocationHandler invocationHandler,
|
|
41 |
| String id, |
|
42 |
| Class clazz, |
|
43 |
| ProxyFactory proxyFactory, |
|
44 |
| InvocationListener invocationListener, |
|
45 |
| ObjectReferenceRetriever objectReferenceRetriever, |
|
46 |
| ExpectationsState expectationsState) { |
|
47 |
713
| this.invocationHandler = invocationHandler;
|
|
48 |
713
| this.id = id;
|
|
49 |
713
| this.clazz = clazz;
|
|
50 |
713
| this.proxyFactory = proxyFactory;
|
|
51 |
713
| this.invocationListener = invocationListener;
|
|
52 |
713
| this.objectReferenceRetriever = objectReferenceRetriever;
|
|
53 |
713
| this.expectationsState = expectationsState;
|
|
54 |
| } |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
1904
| public Object invoke(Object target, Method method, Object[] arguments) throws Throwable {
|
|
60 |
1904
| String methodName = method.getName();
|
|
61 |
1904
| Class[] parameterTypes = method.getParameterTypes();
|
|
62 |
| |
|
63 |
| |
|
64 |
1904
| if (methodName.equals("toString") && parameterTypes.length == 0) {
|
|
65 |
2
| return id;
|
|
66 |
| } |
|
67 |
| |
|
68 |
1902
| if (methodName.equals("equals") && parameterTypes.length == 1 && parameterTypes[0].equals(Object.class)) {
|
|
69 |
147
| return (this.proxy == arguments[0]) ? Boolean.TRUE : Boolean.FALSE;
|
|
70 |
| } |
|
71 |
| |
|
72 |
1755
| if (methodName.equals("hashCode") && parameterTypes.length == 0) {
|
|
73 |
235
| return new Integer(0);
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
1520
| if (methodName.equals("finalize") && arguments.length == 0) {
|
|
78 |
34
| return null;
|
|
79 |
| } |
|
80 |
| |
|
81 |
1486
| sendInvocationListenerEvent(target, arguments, method, invocationListener, objectReferenceRetriever, expectationsState);
|
|
82 |
| |
|
83 |
1486
| MethodHandle methodHandle = new InterfaceMethodHandle(id, method.getName(), parameterTypes, method.getReturnType(), proxyFactory);
|
|
84 |
| |
|
85 |
1486
| return invocationHandler.invocation(id, clazz, methodName, arguments, methodHandle);
|
|
86 |
| } |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
712
| public void setProxy(Object proxy) {
|
|
92 |
712
| this.proxy = proxy;
|
|
93 |
| } |
|
94 |
| } |