Karthick Karthick - 4 years ago 196
Java Question

Getting Error Invalid user of matcher Exception

I have method to to test junit below

public Response submitData(String a, BigInteger b, HttpServletRequest request){
}


I have mockito junit method below

@Test
public void submitData_Success() throws Exception {
when(inAbcExample.submitData(anyString(),eq(new BigInteger("12")),mockRequest)).thenReturn(response);
}


I'm getting invalid use of matcher exception. whether above lines are correct

Answer Source

This error is present when you try to pass some params using the anyXXX() mockito wrappers and yet some of you params are still passed normally (like themockRequest in your case). You should refactor to the following:

@Test
public void submitData_Success() throws Exception {
    when(inAbcExample.submitData(anyString()
           ,Mockito.eq(new BigInteger("12")),Mockito.eq(mockRequest))).thenReturn(response);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download