Can I verify methods called with Method.invoke()?
A simplified version of my code would be something along these lines:
public class MyClass
{
public void callMethod(Object callbackObject, String methodName)
{
Class<?> theClass = callbackObject.getClass();
method = theClass.getMethod(methodName);
method.invoke(callbackObject);
}
}
public MyClassTest
{
public void testCallMethod()
{
Object mockObject = mock(Object.class);
String testMethod = "toString()";
MyClass class = new MyClass();
class.callMethod(mockObject, testMethod);
verify(mockObject).toString();
}
}
Should this work?
Thanks,
-Pato
-Pato
It should work just fine. Not sure what you mean by class other than
Object. Mockito verifications / stubbing will work fine for:
- invoking methods explicitly (foo.bar())
- invoking methods via reflection: Foo.class.getMethod("bar").invoke(....
Cheers,
Szczepan Faber
> --
> You received this message because you are subscribed to the Google Groups "mockito" group.
> To post to this group, send email to moc...@googlegroups.com.
> To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mockito?hl=en.
>
>
>
>
Now, I know there is something special about stubbing or verifying
toString(); could that be cause?
-Pato
On 11 ene, 18:03, szczepiq <szcze...@gmail.com> wrote:
> Hi,
>
> It should work just fine. Not sure what you mean by class other than
> Object. Mockito verifications / stubbing will work fine for:
> - invoking methods explicitly (foo.bar())
> - invoking methods via reflection: Foo.class.getMethod("bar").invoke(....
>
> Cheers,
> Szczepan Faber
>
Cheers!
Szczepan Faber