I am trying to use Mockito.verify(mock).method(object). What I am trying to accomplish is to check if the method was called with object parameter when testing.
verify(mock).method(object);
where object is something like:
public class Object {
private static final string PROPERTY = "property";
}
It seems like value of properties are same, but it still thinks it is different because they are not actual same object. What is the best way to handle this? My initial approach is to use @Captor and check each value one at a time. Is there better way than this?
There are auxiliary methods in Mockito to handle this.
For example, define “equals” in the Object
and then you can use:
verify(mock).method(Mockito.eq(object));
Besides eq
there are many other methods that might be handy ( same
, any*
) etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.