1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.test.mock; |
17 |
|
|
18 |
|
import java.lang.reflect.InvocationHandler; |
19 |
|
import java.lang.reflect.Method; |
20 |
|
import java.lang.reflect.Proxy; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
|
25 |
|
@author |
26 |
|
|
27 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
28 |
|
public class MockProxy implements InvocationHandler { |
29 |
|
private Map<String,Object> methodReturnMap; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@param |
42 |
|
@param |
43 |
|
@param |
44 |
|
@return |
45 |
|
@throws |
46 |
|
@throws |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
0
|
@SuppressWarnings("unchecked")... |
49 |
|
public static <T> T newInstance(Map<String,Object> methodReturnMap, Class<T> interfaceClass) throws InstantiationException, IllegalAccessException { |
50 |
0
|
return (T)Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass }, new MockProxy(methodReturnMap)); |
51 |
|
} |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
53 |
0
|
private MockProxy(Map<String,Object> methodReturnMap) {... |
54 |
0
|
super(); |
55 |
0
|
this.methodReturnMap = methodReturnMap; |
56 |
|
|
57 |
0
|
if(this.methodReturnMap==null){ |
58 |
0
|
this.methodReturnMap = new HashMap<String, Object>(); |
59 |
|
} |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0
|
public MockProxy() {... |
63 |
0
|
super(); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
@see |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
69 |
0
|
@Override... |
70 |
|
public Object invoke(Object proxy, Method method, Object[] args) |
71 |
|
throws Throwable { |
72 |
0
|
Object result = methodReturnMap.get(method.getName()); |
73 |
|
|
74 |
0
|
if (result instanceof MockArgumentMapper){ |
75 |
0
|
result = ((MockArgumentMapper)result).getReturnValue(args); |
76 |
|
} |
77 |
|
|
78 |
0
|
return result; |
79 |
|
} |
80 |
|
|
81 |
|
} |