Thanks for taking a look at Mockito.
Correct, the current behavior is it will return the last stubbed
value, but I wonder do you relay need it ?
With Mockito you don't have to stub as many times as the method will
be invoked later, so
stub(mock.receive()).toReturn(message);
will satisfy any number of mock.receive() invocations and those
invocations won't be verified, you have to explicitly state how many
times you expect receive invocation to happen.
stub(mock, times(3)).receive(); //exactly 3 times
or maybe a little bit loosen constraint
stub(mock, atLeastOnce()).receive(); // any number but no less then 1
If you have any further question, don't hesitate to ask.
Cheers,
Igor
I thought you may need this functionality to test various conditional
login in the code, but for me these should be separate test cases. One
for each type of message. Unfortunately, when dealing with mocks each
test forces you to repeat the verification steps. More you can find
here http://www.martinfowler.com/articles/mocksArentStubs.html
However, when you don't use in order verification, I wouldn't afraid
to extract common verification steps to separate method with an
appropriate name and just add the parts of interactions, that differs
for various types of messages, afterwards
Nevertheless, we put this functionality on our TODO list and when more
requests come it will probably find it's place within Mockito.
If you can past some code here, we can work it out together to come
up with solution.
Cheers,
Igor
It was based on a production code where plain JDBC is used and
ResultSet is my "iterator". I will try to find a part which I can send
here later on.
> Simplified stubbing promotes smaller test methods, where you stub per single
> scenario. At least I hope so :)
I gave you a single scenario which requires more advanced stubbing.
On the other hand I completely agree that stubs should be as simple as
possible. The same is true for test methods. One scenario for one test
method is what I always follow.
Regards,
Bartosz
> Do you still want chained return values in Mockito?
No and I don't have anything more to show you :) I will try your
solution next time!
Thanks,
Bartosz
2008/3/3 szczepiq <szcz...@gmail.com>: