Skip to content

Conversation

@m-koops
Copy link
Contributor

@m-koops m-koops commented Jan 17, 2026

This PR fixes #573

The CoroutineAwareAnswer has been enhanced to properly handle stubbing of return values of type Result.

I started off with the sample test cases provided in PR #574, but I've added many more tests to cover the many (hopefully all) variations of Result return values. It turns out that it depends much on the nested value of a Return whether it needs unboxing or not when passing it on into the Java code of Mockito-core.

I've tried to set up the many new tests as parameterized tests in JUnit, but with JUnit4 that turns out a bit tedious.
Things would be way easier if the project is migrated to JUnit5, so that is likely something to dive into in the near future.

@TimvdLippe
Copy link
Contributor

@jselbo FYI

@m-koops m-koops changed the title Help needed: Improve support for stubbing Result return values for suspendable functions Improve support for stubbing Result return values for suspendable functions Jan 18, 2026
@m-koops m-koops marked this pull request as ready for review January 18, 2026 12:13
@m-koops
Copy link
Contributor Author

m-koops commented Jan 18, 2026

@jselbo FYI

@TimvdLippe @jselbo the PR is ready for review.

@m-koops
Copy link
Contributor Author

m-koops commented Jan 20, 2026

I noticed that I was so focus on fixing Result return values for suspend functions that I overlooked adding similar test cases for synchronous stubs. Those tests (and a fix to get them working) have now been added.

@jselbo @TimvdLippe Any chance to get this PR reviewed/merged soon?

@m-koops m-koops changed the title Improve support for stubbing Result return values for suspendable functions Improve support for stubbing Result return values for synchronous and suspendable functions Jan 20, 2026
Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lack the Kotlin knowledge to understand all the details, but given the extensive test coverage I trust that's okay. Thanks again for polishing!

@TimvdLippe TimvdLippe merged commit d0492b0 into mockito:main Jan 21, 2026
3 checks passed
@m-koops
Copy link
Contributor Author

m-koops commented Jan 21, 2026

Thank you very much @TimvdLippe. And many thanks for releasing 6.2.2 including this fix and #579.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stubbing with Result<Boolean> broken in 6.2.0

2 participants