New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong value when mocking kotlin.Result #867
Comments
I'm facing the same issue. The following test works with 1.12.4 but not with 1.12.5: interface Source {
fun getData(): Result<Boolean>
}
interface View {
fun showError()
fun showData()
}
class TestSubject(
private val source: Source,
private val view: View,
) {
fun execute() {
val result = source.getData()
when {
result.isFailure -> view.showError()
result.getOrThrow() -> view.showData()
}
}
}
class ValueClassTest : WordSpec({
val source = mockk<Source>()
val view = mockk<View>()
val subject = TestSubject(source, view)
beforeEach {
clearMocks(
source,
view,
)
}
"execute" should {
"show data" {
every { source.getData() } returns Result.success(true)
subject.execute()
verify {
view.showData()
}
}
"show error" {
every { source.getData() } returns Result.failure(NullPointerException())
subject.execute()
verify {
view.showError()
}
}
}
}) |
This comment was marked as duplicate.
This comment was marked as duplicate.
I'm facing the same issue with |
Should be fixed by #872 |
It was fixed with recent version |
Unfortunately, something apparently went wrong with publishing that release. |
Looks good on |
Seems like the issue comes back. I have the version io.mockk:mockk:1.13.2 |
Why was this closed, if not fixed? |
Read above, there seems to be a regression. |
I also encountered this issue recently in
Error: Cannot invoke "kotlin.Result.unbox-impl()" because the return value of "LoadingStateHolder.getCurrentState()" is null |
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Failure Information (for bugs)
In mockk 1.12.4 I was able to mock a
kotlin.Response
return value on a function and get the generic value from it.1.12.5 seems to have broken this and regardless of the
Response.success(x)
value, success always folds to a booleanfalse
.Code below.
Context
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: