David Selvaraj
unread,Apr 26, 2012, 4:39:50 PM4/26/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mockito
I have a method that converts jason string to a list. The signature
of the method is
public static <T> List<T> mapJsonToObjectList(T typeDef, String json,
Class<?> clazz)
I trying to simulate an exception scenario by throwing an exception
then this method is called and using Mockito to mock this method call
by saying
when(MapUtils.mapJsonToObjectList(Mockito.any(),anyString(),Mockito.any(Class.class))).thenThrow((new
Exception ()));
I am getting an exception
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced argument matcher detected here:
You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
when(mock.get(anyInt())).thenReturn(null);
doThrow(new
RuntimeException()).when(mock).someVoidMethod(anyObject());
verify(mock).someMethod(contains("foo"))
Also, this error might show up because you use argument matchers with
methods that cannot be mocked.
Following methods *cannot* be stubbed/verified: final/private/equals()/
hashCode().
Can someone please let me know how to stub this method?
Thanks,
David