| 1 | |
package biz.xsoftware.mock; |
| 2 | |
|
| 3 | |
import java.io.Serializable; |
| 4 | |
import java.lang.reflect.Method; |
| 5 | |
import java.util.Arrays; |
| 6 | |
import java.util.List; |
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
public final class CalledMethod implements Serializable { |
| 15 | |
|
| 16 | |
private static final long serialVersionUID = -4453563617218618682L; |
| 17 | |
|
| 18 | |
private final String methodName; |
| 19 | |
|
| 20 | |
private final Method method; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
private final Object[] params; |
| 27 | |
|
| 28 | |
private final Throwable howItWasCalled; |
| 29 | |
|
| 30 | 5 | public CalledMethod(String methodName, Object[] params, Throwable howItWasCalled) { |
| 31 | 5 | this.methodName = methodName; |
| 32 | 5 | this.method = null; |
| 33 | 5 | if (params!=null) { |
| 34 | 0 | this.params = params.clone(); |
| 35 | 0 | } else { |
| 36 | 5 | this.params = null; |
| 37 | |
} |
| 38 | 5 | this.howItWasCalled = howItWasCalled; |
| 39 | 5 | } |
| 40 | |
|
| 41 | 342 | public CalledMethod(String methodName, Method method, Object[] params, Throwable howItWasCalled) { |
| 42 | 342 | this.methodName = methodName; |
| 43 | 342 | this.method = method; |
| 44 | 342 | if (params!=null) { |
| 45 | 196 | this.params = params.clone(); |
| 46 | 196 | } else { |
| 47 | 146 | this.params = null; |
| 48 | |
} |
| 49 | 342 | this.howItWasCalled = howItWasCalled; |
| 50 | 342 | } |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public String getMethodName() { |
| 58 | 472 | return methodName; |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public Method getMethod() { |
| 66 | 0 | return method; |
| 67 | |
} |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public int getParameterCount() { |
| 75 | 1 | return params.length; |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public Object getParameter(int index) { |
| 85 | 20 | return params[index]; |
| 86 | |
} |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
public Object[] getAllParams() { |
| 98 | 17 | return params.clone(); |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
public Throwable getHowItWasCalled() { |
| 108 | 12 | return howItWasCalled; |
| 109 | |
} |
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public String toString() { |
| 113 | 0 | List<Object> paramList = null; |
| 114 | 0 | if (params != null) |
| 115 | 0 | paramList = Arrays.asList(params); |
| 116 | |
|
| 117 | 0 | return "[method=" + method + " params=" + paramList + "]"; |
| 118 | |
} |
| 119 | |
} |