mockito-kotlin
mockito-kotlin copied to clipboard
How to mock lambda call
Hello, I have this function:
override fun loadSensors(userId: String, param: (Result<MutableList<UserSensor>>) -> Unit) {
// Blank
}
@get:Rule
var hiltRule = HiltAndroidRule(this)
@Rule @JvmField
var mockitoRule = MockitoJUnit.rule()
@Inject
lateinit var repository: MockRepositoryImpl
@Before
fun before() {
hiltRule.inject()
MockitoAnnotations.openMocks(this)
`when`(repository.loadSensors(anyString(), any())).thenAnswer {
Result.Success("", mutableListOf(UserSensor(0), UserSensor(1)))
}
ActivityScenario.launch(MainActivity::class.java)
}
How to mock that thenAnswer
would actually call my param
argument?
Are you asking about InvocationOnMock
?