Is it possible to mock accessors by Mockito in Kotlin?

To mock getter just write:

val m = mock<Ddd>()
`when`(m.qq).thenReturn("42")

also i suggest to use mockito-kotlin, to use useful extensions and functions like whenever:

val m = mock<Ddd>()
whenever(m.qq).thenReturn("42")

Complementing IRus' answer, you could also use the following syntax:

val mockedObj = mock<SomeClass> {
  on { funA() } doReturn "valA"
  on { funB() } doReturn "valB"
}

or

val mockedObj = mock<SomeClass> {
  on(it.funA()).thenReturn("valA")
  on(it.funB()).thenReturn("valB")
}

Tags:

Mockito

Kotlin