Mockito: Verifying with generic parameters

后端 未结 4 1035
北海茫月
北海茫月 2020-12-02 19:34

With Mockito I can do the following:

verify(someService).process(any(Person.class));

But how do I write this if process takes

4条回答
  •  猫巷女王i
    2020-12-02 20:11

    You can't express this because of type erasure. Even if you could express it in code, Mockito had no chance to check it at runtime. You could create an interface like

    interface PersonCollection extends Collection { /* nothing */ }
    

    instead and use this throughout your code.

    Edit: I was wrong, Mockito has anyCollectionOf(..) which is what you want.

提交回复
热议问题