Mockito:使用泛型参数进行验证

使用 Mockito,我可以做到以下几点:

With Mockito I can do the following:

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

但是,如果 process 采用 Collection 代替,我该怎么写呢?无法弄清楚如何正确编写它.只是遇到语法错误...

But how do I write this if process takes a Collection<Person> instead? Can't figure out how to write it correctly. Just getting syntax errors...

推荐答案

试试:

verify(someService).process(Matchers.<Collection<Person>>any());

实际上,当我键入 any() 时,IntelliJ 会自动建议此修复程序...不幸的是,在这种情况下您不能使用静态导入.

Actually, IntelliJ automatically suggested this fix when I typed any()... Unfortunately you cannot use static import in this case.

相关文章