mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.11k stars 201 forks source link

Ho to check the copy of a mock? #339

Closed tofas closed 5 years ago

tofas commented 5 years ago

I have this mocked object in my test:

private val model: UiModel = mock { on{ status } doReturn PURCHASED }

and I want to test the return of this method:

fun refreshStatus(model: UiModel): UiModel { return model.copy(status = CANCELLED) }

I want to check if that new uiModel has updated the status, but it seems that copy method over a mock is returning null

val model = mapper.refreshStatus(uiModel) assertEquals(model.status, CANCELLED)

Is this possible or even make sense?

bohsen commented 5 years ago

You don't need a mock of your model. You should just pass in a regular model with status set to PURCHASED or am I missing something?

tofas commented 5 years ago

I was refactoring to Kotlin some clases and tests and wasn't sure if that test make sense at all. Thanks for answering anyway, I'm still learning abut kotlin and how to do proper unit tests with it's specific methods like .copy().