Reputation: 4719
Given a method definition as follows:
MyClass.myMethod(SecondClass secondClass);
and a mock of MyClass:
MyClass myClass = mock(MyClass.class);
how would you match the method parameter when defining the expecation?
when(myClass.myMethod(???)).thenReturn(null);
Thanks
Upvotes: 1
Views: 79
Reputation: 22812
when(myClass.myMethod(Mockito.any(SecondClass.class))).thenReturn(null);
Upvotes: 1
Reputation: 16185
Actually the best way to do it is
doReturn(object).when(myClass).myMethod(???);
in ???
you have some possibilities.
You can pass a given object and then you wait for an especific one
Or you can pass Mockito.any(Clazz.class)
and then you will accept any object of that kind
Upvotes: 0