mockito报错cannot use argument matchers outside of verification?

mockito报错cannot use argument matchers outside of verification?


interface IAccountService : IService<AccountInfo> {
    fun simpleInfo(id: Long): AccountInfo?
    fun register(accountInfo: AccountInfo): Boolean


class AccountServiceImpl : IAccountService, ServiceImpl<AccountMapper, AccountInfo>() {
    override fun simpleInfo(id: Long): AccountInfo? {
        val simpleInfo = baseMapper.simpleInfo(id);
        return simpleInfo
    override fun register(accountInfo: AccountInfo): Boolean {
        return baseMapper.insert(accountInfo) > 0


data class AccountInfo (
     var uid: Long? = null,
     // 用户名
     var username: String? = null,
     // 用户昵称
     var nickname: String? = null,
) {


class AccountControllerTest {
     lateinit var mockMvc: MockMvc
     private lateinit var accountService: IAccountService
     fun register() {
       val simpleInfo = accountService.simpleInfo(1L)

运行上边的测试,simpleInfo方法可以正常执行,但是当执行 register测试方法的第三行的when时,报以下错误:

You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());

This message may appear after an NullPointerException if the last matcher is returning an object 
like any() but the stubbed method signature expect a primitive argument, in this case,
use primitive alternatives.
    when(mock.get(any())); // bad use, will raise NPE
    when(mock.get(anyInt())); // correct usage use

Also, this error might show up because you use argument matchers with methods that cannot be mocked.
Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
Mocking methods declared on non-public parent classes is not supported.