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

Stubbing method same params value twice on same mock take the first one not last one #21

Closed
Wolfium opened this issue Apr 26, 2017 · 4 comments

Comments

@Wolfium
Copy link

Wolfium commented Apr 26, 2017

Indented behavior is last stubbing is more important and should be used.

when(mock(mockObject.method())).thenReturn(false);
when(mock(mockObject.method())).thenReturn(true);

Return false.
it should return last stubbing value, true.

when(mock(mockObject.method())).thenReturn(false);
reset(mockObject);
when(mock(mockObject.method())).thenReturn(true);

Workaround calling reset before next stubbing duplicate, but would be great be default simpler usage and does not reset the whole object.

Regards

@NagRock
Copy link
Owner

NagRock commented Apr 26, 2017

Thanks for reporting it. It will be default behavior in 2.0 version that will be available in a few days.

@Wolfium
Copy link
Author

Wolfium commented Apr 26, 2017 via email

@NagRock
Copy link
Owner

NagRock commented Apr 28, 2017

Should be fixed in 2.0 version. Please reopen if something is still wrong.

@NagRock NagRock closed this as completed Apr 28, 2017
@NagRock
Copy link
Owner

NagRock commented Apr 28, 2017

@Wolfium
Also you should not call mock() method inside when():

const mockObject = mock(YourClass);
when(mockObject.method()).thenReturn(false);

instead of:

when(mock(mockObject.method())).thenReturn(false);

johanblumenberg pushed a commit to johanblumenberg/ts-mockito that referenced this issue Aug 12, 2022
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

No branches or pull requests

2 participants