错误信息: org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 1 matchers expected, 2 recorded: ... This exception may occur if matchers are combined with raw values: //incorrect: someMethod(anyObject(), "raw String"); When using matchers, all arguments have to be provided by matchers. For example: //correct: someMethod(anyObject(), eq("String by matcher")); For more info see javadoc for Matchers class.
划重点:
//incorrect: someMethod(anyObject(), "raw String"); //correct: someMethod(anyObject(), eq("String by matcher"));
如果方法中使用any匹配当作入参,那么全部入参都要使用匹配器,想要在使用any匹配同时传入固定参数可以使用eq()
\