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

Incorrect behaviour for andStubReturn() #52

henri-tremblay opened this Issue Jun 3, 2015 · 0 comments


None yet
1 participant

henri-tremblay commented Jun 3, 2015

Migrated from: CodeHaus issue EASYMOCK-41
Original reporter: Henri Tremblay

In EasyMock 1.x you could use setDefaultReturnValue() to stub a default return value for a method call but you could also change the default return value by simply calling setDefaultReturnValue() again, with a new value. We have over 20000 tests and a significant number of these make use of this "feature". Notably, in a call to reset, we often reset the default return value for various state machines, but from time to time we may need to state to be different at the start of a test. We achieve this by then setting then default value for the same method call with a new value. From EasyMock 2.x onwards, this is no longer possible to set the default return value/stubbed return value multiple times with different values between calls to reset.

I had a look at the source for 2.5.2 specifically and noticed that the MocksBehaviour.addStub() does not look for an existing expected invocation before adding a new invocation and result object. This in itself is not wrong, but the MocksBehaviour.getStubResult() is iterating through the list of stubbed values and returning as soon as it finds the first one! This would seem to indicate that there should be only one stubbed value per mock method call.

I offer the attached SVN patch file for your consideration that will enable MocksBehaviour.addStub() to determine if an existing invocation and result exists and replace the stubbed result if applicable. This would re-enable the 1.x functionality and eliminate the ability to add multiple redundant stubbed values.

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