Skip to content
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

Trying to set an expectation on unsupported method messes up Mockito internal state. #551

Open
yanok opened this issue Jul 28, 2022 · 2 comments
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@yanok
Copy link
Contributor

yanok commented Jul 28, 2022

Currently if one generates mocks with

@GenerateMocks(customMocks: MockSpec<Foo>(unsupportedMembers: {#m})

and then trying to set an expectation on foo.m, not only the test trying to do this fails (which is expected), but also all the following tests, since unsupported method throws without cleaning _storedArgs/_storedNamedArgs and that messes up Mockito internal state.

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jul 28, 2022
@iinozemtsev
Copy link
Member

It's broader than this, internal state is also messed if thenReturn doesn't succeed:
when(mock).thenReturn(null!)

Probably no easy fix in mockito for this, but maybe an error message can be improved with possible explanations

@yanok
Copy link
Contributor Author

yanok commented Aug 18, 2023

Could be potentially fixed with #684. Actually I think we could get rid of internal state altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants