Reputation: 525
I try to use Mockito to mock the getDeclaredMethod()
of java.
but the parameter of this method is un-certain. how to mock such method?
public Method getDeclaredMethod(String name, Class... parameterTypes) throws NoSuchMethodException, SecurityException {
throw new RuntimeException("Stub!");
}
Upvotes: 6
Views: 688
Reputation: 40048
Matches anything, including nulls and varargs.
Example
when(mockedObject.getDeclaredMethod(anyString(),any())).thenReturn("element");
In your case
when(mockedObject.getDeclaredMethod(anyString(), (Class<?>)any())).thenReturn("element");
And also anyVararg() but which is Deprecated. as of 2.1.0
Upvotes: 4