dimanche 28 août 2016

mockito partial parmaters mocking

I am trying to write unit test in java. Below is snippet of my code

class Temp { public void method() {

       return someObject.someMethod(param1, param2, param3, param4, param5);
   }
}

Test Method:

@Test
public void testMethod() {

     Mokito.when(someObjectMock.someMethod(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyBoolean(),
                    false)). thenReturn(true);

     boolean status = temp.method();

     Assert.assertEquals(true, status);
}

On executing the test case, I am however getting below error:

 Invalid Use of argument matchers !
 5 matchers expected, 4 recorded

If my understanding is correct, it expects all parameters passed to be mocked. However thats not what I want, I wish to mock the first 4 parameters, and based on the 5 parameter (true or false), then appropriate return value of the method will specified.

Is there way to get around this?

Thanks

Aucun commentaire:

Enregistrer un commentaire