Good morning everyone. Given the following code, i...
# mockk
d
Good morning everyone. Given the following code, is there an obvious reason why the mocked objects return their default values instead of the mocked ones inside the verify block?
Copy code
val libriOrder = mockk<LibriOrder> {
            every { blueOrderUuid } returns UUID.randomUUID()
            every { items } returns libriOrderItems
        }

        subject.libriOrderItemCancelled(...)

        verify {
            blueOrderService.cancelOrderItem(
                libriOrder.blueOrderUuid,
                cancelledLibriOrderItem.blueOrderItemId
            )
        }
So basically the assertion fails and when inspecting the variables inside the verify block, `libriOrder.blueOrderUuid`is null and
cancelledLibriOrderItem.blueOrderItemId
is 0
And this works just fine too
Copy code
val blueOrderUuid = libriOrder.blueOrderUuid
        val blueOrderItemId = cancelledLibriOrderItem.blueOrderItemId

        verify { blueOrderService.cancelOrderItem(blueOrderUuid, blueOrderItemId) }
m
yep mocking does not work inside
verify
blocks you should be doing something like
Copy code
val libriOrder = mockk<LibriOrder> {
    every { blueOrderUuid } returns 123
}

subject.libriOrderItemCancelled(...)

verify {
    blueOrderService.cancelOrderItem(123...)
}
but calling the
blueOrderUuid
property inside a verify block does not call its mocked function
d
Good to know, thank you. Is this documented somewhere?