-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Issue 2544 #2545
Issue 2544 #2545
Conversation
…tructionWithAnswer(). If you build a mockConstructionWithAnswer with more than 1 additionalAnswers there was a logic error whereby the method would return the wrong value when making the second last invocation. It would accidentally think it's at the end an only return the last answer, never returning the second last answer when it should. The changes I made to ConstructionMockTest.java now exercises this condition.
…tructionWithAnswer(). If you build a mockConstructionWithAnswer with more than 1 additionalAnswers there was a logic error whereby the method would return the wrong value when making the second last invocation. It would accidentally think it's at the end an only return the last answer, never returning the second last answer when it should. The changes I made to ConstructionMockTest.java now exercises this condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and easy fix! Only a tiny nit with regards to the test.
@@ -50,10 +50,11 @@ public void testConstructionMockDefaultAnswer() { | |||
|
|||
@Test | |||
public void testConstructionMockDefaultAnswerMultiple() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we retain the original test (e.g. 2 invocation definitions and invoking it 3 times) and instead add a new regression test which is this new format? That way we ensure that both scenarios still work, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I restored testConstructionMockDefaultAnswer() in ConstructionMockTest to it's original 2-invocation form. I added new test, testConstructionMockDefaultAnswerMultipleMoreThanTwo() to demonstrate the code is now fixed when more than 2 invocations are in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Spring Boot Version 2.4.3 adds org.mockito package with version 3.6.8. There is a bug with this version: mockito/mockito#2545 So we need to keep additional invocation.
Fixed issue 2544.
Mockito.mockConstructionWithAnswer() has a bug when there are more than 2 invocations possible.
If you run the ConstructionMockTest.testConstructionMocDefaultAnswerMultiple() as this:
It works fine.
But if you change it to this:
It will fail when trying to assert
qux
. It's because there is an error in the conditional logic in theelse if (context.getCount() >= additionalAnswers.length)
. It should be>
not>=
.