1
|
|
|
2
|
|
package org.jmock.dynamic;
|
3
|
|
|
4
|
|
import java.lang.reflect.Method;
|
5
|
|
import java.lang.reflect.Proxy;
|
6
|
|
import java.util.*;
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
public class Invocation {
|
16
|
|
private String name;
|
17
|
|
private List parameterTypes;
|
18
|
|
private Class returnType;
|
19
|
|
private List parameterValues;
|
20
|
|
|
21
|
174
|
public Invocation(String name, Class[] parameterTypes,
|
22
|
|
Class returnType, Object[] parameterValues) {
|
23
|
174
|
this.name = name;
|
24
|
174
|
this.parameterTypes = Arrays.asList(parameterTypes);
|
25
|
174
|
this.returnType = returnType;
|
26
|
174
|
if (parameterValues == null) {
|
27
|
50
|
this.parameterValues = new ArrayList(0);
|
28
|
|
} else {
|
29
|
124
|
this.parameterValues = Arrays.asList(parameterValues);
|
30
|
|
}
|
31
|
|
}
|
32
|
|
|
33
|
76
|
public Invocation(Method method, Object[] parameterValues) {
|
34
|
76
|
this(method.getName(), method.getParameterTypes(),
|
35
|
|
method.getReturnType(), parameterValues);
|
36
|
|
}
|
37
|
|
|
38
|
52
|
public String getMethodName() {
|
39
|
52
|
return name;
|
40
|
|
}
|
41
|
|
|
42
|
4
|
public List getParameterTypes() {
|
43
|
4
|
return Collections.unmodifiableList(parameterTypes);
|
44
|
|
}
|
45
|
|
|
46
|
72
|
public List getParameterValues() {
|
47
|
72
|
return Collections.unmodifiableList(parameterValues);
|
48
|
|
}
|
49
|
|
|
50
|
4
|
public Class getReturnType() {
|
51
|
4
|
return returnType;
|
52
|
|
}
|
53
|
|
|
54
|
10
|
public String toString() {
|
55
|
10
|
return DynamicUtil.methodToString(name, parameterValues.toArray());
|
56
|
|
}
|
57
|
|
|
58
|
54
|
public boolean equals(Object o) {
|
59
|
54
|
if (o instanceof Invocation) {
|
60
|
52
|
return this.equals((Invocation) o);
|
61
|
|
} else {
|
62
|
2
|
return false;
|
63
|
|
}
|
64
|
|
}
|
65
|
|
|
66
|
4
|
public int hashCode() {
|
67
|
4
|
return name.hashCode() ^
|
68
|
|
listHashCode(parameterTypes) ^
|
69
|
|
returnType.hashCode() ^
|
70
|
|
listHashCode(parameterValues);
|
71
|
|
}
|
72
|
|
|
73
|
8
|
private int listHashCode(List array) {
|
74
|
8
|
int hashCode = 0;
|
75
|
8
|
for (Iterator i = array.iterator(); i.hasNext();) {
|
76
|
16
|
hashCode ^= i.next().hashCode();
|
77
|
|
}
|
78
|
8
|
return hashCode;
|
79
|
|
}
|
80
|
|
|
81
|
66
|
public boolean equals(Invocation call) {
|
82
|
66
|
return call != null
|
83
|
|
&& name.equals(call.name)
|
84
|
|
&& parameterTypes.equals(call.parameterTypes)
|
85
|
|
&& returnType.equals(call.returnType)
|
86
|
|
&& parameterValues.equals(call.parameterValues);
|
87
|
|
}
|
88
|
|
|
89
|
56
|
boolean isCheckingEqualityOnProxy() {
|
90
|
56
|
return name.equals("equals")
|
91
|
|
&& parameterValues.size() == 1
|
92
|
|
&& parameterValues.get(0) != null
|
93
|
|
&& Proxy.isProxyClass(parameterValues.get(0).getClass());
|
94
|
|
}
|
95
|
|
|
96
|
54
|
boolean isMockNameGetter() {
|
97
|
54
|
return name.equals("getMockName")
|
98
|
|
&& parameterValues.size() == 0;
|
99
|
|
}
|
100
|
|
}
|
101
|
|
|