forked from mockito/mockito
/
InvocationOnMock.java
91 lines (81 loc) · 2.69 KB
/
InvocationOnMock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.invocation;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.mockito.NotExtensible;
/**
* An invocation on a mock.
*
* <p>
* A placeholder for mock, the method that was called and the arguments that were passed.
*/
@NotExtensible
public interface InvocationOnMock extends Serializable {
/**
* returns the mock object
*
* @return mock object
*/
Object getMock();
/**
* returns the method
*
* @return method
*/
Method getMethod();
/**
* Returns arguments passed to the method.
*
* Vararg are expanded in this array.
*
* @return arguments
*/
Object[] getArguments();
/**
* Returns casted argument at the given index.
*
* Can lookup in expanded arguments form {@link #getArguments()}.
*
* This method is preferred over {@link #getArgument(int, Class)} for readability. Please read
* the documentation of {@link #getArgument(int, Class)} for an overview of situations when
* that method is preferred over this one.
*
* @param index argument index
* @return casted argument at the given index
* @since 2.1.0
*/
<T> T getArgument(int index);
// Todo: add getRawArguments to this interface?
/**
* Returns casted argument at the given index. This method is analogous to
* {@link #getArgument(int)}, but is necessary to circumvent issues when dealing with generics.
*
* In general, {@link #getArgument(int)} is the appropriate function to use. This particular
* function is only necessary if you are doing one of the following things:
*
* <ol>
* <li>You want to directly invoke a method on the result of {@link #getArgument(int)}.</li>
* <li>You want to directly pass the result of the invocation into a function that accepts a generic parameter.</li>
* </ol>
*
* If you prefer to use {@link #getArgument(int)} instead, you can circumvent the compilation
* issues by storing the intermediate result into a local variable with the correct type.
*
* @param index argument index
* @param clazz class to cast the argument to
* @return casted argument at the given index
*/
<T> T getArgument(int index, Class<T> clazz);
/**
* calls real method
* <p>
* <b>Warning:</b> depending on the real implementation it might throw exceptions
*
* @return whatever the real method returns / throws
* @throws Throwable in case real method throws
*/
Object callRealMethod() throws Throwable;
}