The myMethod method is myMethod . But it is called on the layout of the object - this is a "trick".
Of course, you can write code that accepts a "method pointer" (in Java, it will be an object of the Method class) and some arguments, and use invoke , but it will not actually buy you anything over calling the mock object myMethod directly.
Most common when :
MyObject myObject = mock(MyObject.class); when(myObject.myMethod("abc", 123)).thenReturn(456);
Try to print (or register) the expression
myObject.getClass().getName()
here. You will see that the mock object class is not really MyObject . But this is a class that has the same interface. Calls to this object update some internal state. This allows Mockito to keep track of how it is used, and allows you to state various things.
source share