java.lang.reflect.InvocationTargetException when using Kotlin-Mokito library

前端 未结 1 1758
一个人的身影
一个人的身影 2021-01-14 21:51

any() from Kotlin Mockito library crash with the following code

The Test Class

import com.nhaarman.mockito_kotlin.any
import com.nha         


        
1条回答
  •  一生所求
    2021-01-14 22:10

    The library relies on the reflection to instantiate an object of a given type to be used as mockito "Any" object. It might not be possible for those classes which have non-trivial constructors. Response is one of them.

    If you could get an instance of Response somehow, you can use it instead like:

    verify(injectedObject).settingDependentObject(Mockito.any() ?: someResponse)
    

    0 讨论(0)
提交回复
热议问题