I'm trying to do some testing in my object kotlin class, but I can getting an error in my thenReturn method when I try to pass the object. I get a Require: Unit! Found checkout. Someone can point me how is possible to test it??
If I remove thenReturn method I get this error:
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, which is not supported
3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
I refer this link but I can't get it.
object CheckoutRepository: CheckoutContract.Model {
var checkout: MutableList<Checkout> = mutableListOf<Checkout>()
override fun addProductToShoppingCart(checkoutProduct: Checkout){
checkout.add(checkoutProduct)
}
override fun getProductsInShoppinCart() : List<Checkout>?{
return checkout
}
override fun cleanCheckout(){
checkout.clear()
}
}
@Test
fun test_with_mock() {
val mock = mock<CheckoutContract.Model>()
var checkout = Checkout("VOUCHER", "voucher", 35.0, 5)
mock.addProductToShoppingCart(checkout)
val answer = mock.getProductsInShoppinCart()
`when`(mock.addProductToShoppingCart(checkout)).thenReturn(checkout)
assertNotNull(checkout)
assertEquals(checkout, answer)
}