Mockito: How to verify a method was called only once with exact parameters ignoring calls to other methods?

前端 未结 3 685
天涯浪人
天涯浪人 2020-12-28 12:15

Using Mockito in Java how to verify a method was called only once with exact parameters ignoring calls to other methods?

Sample code:

public class Mo         


        
3条回答
  •  情歌与酒
    2020-12-28 13:00

    The previous answer can be simplified even further.

    Mockito.verify(foo).add("1");
    Mockito.verify(foo).add(Mockito.anyString());
    

    The single parameter verify method is just an alias to the times(1)implementation.

提交回复
热议问题