I would like to mock a property setter in my test, but I can't find anything on how one does it. Here is what I have tried so far:
interface Foo
{
var property: Int
}
@RunWith(MockitoJUnitRunner::class)
class TestClass
{
@Mock private val fooMock: Foo = mock()
private var temp = 0
@Before
fun setup()
{
whenever(fooMock.property).then {
invocation ->
if (invocation.arguments.isEmpty())
{
// this part works fine
return@then 15
}
else
{
// this never gets called
temp = invocation.getArgument(0)
null
}
}
}
}
note: I am using com.nhaarman.mockito_kotlin library