Re: [mockito] Mockito: multiple calls to the same method do not work with thenAnswer()

843 views
Skip to first unread message

Brice Dutheil

unread,
Nov 20, 2012, 10:37:31 AM11/20/12
to moc...@googlegroups.com
Nope, I don't htink there's a bug in Mockito on this front. If you are using thenReturn, then the return value will be returned for each interaction, if you are using thenAnswer, this is the given that will be used forever. Of course unless you write another stub for the same interactions, which will replace the previous one.


on SO, Jonathan's answer looks like the best approach. Plus your comment show that you actually have two different test scenario, your unit test should express them in distinct test method name. Using answer directly this way look britle to me, especially if your actual test doesn't distinct the 2 different behavior you described.

If however your test for example with threads and the first interaction may or may not happen before the other, then null should be expected, right ?


Hope that helps.
Cheers,
-- Brice



On Tue, Nov 20, 2012 at 3:36 PM, Ula K. <ukr...@gmail.com> wrote:
Please see this StackOverflow question for details: http://stackoverflow.com/questions/13475057/mockito-multiple-calls-to-the-same-method

Basically, Mockito documentation says that stubbed method will return specified value for all subsequent calls. It seems this is not true if method was stubbed using thenAnswer().

Possible bug?

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/2FwzRE4hyFAJ.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.

Ula K.

unread,
Nov 29, 2012, 5:21:39 AM11/29/12
to moc...@googlegroups.com
As always, bug was on my side, not on Mockito's side. Check SO for details.

Brice Dutheil

unread,
Nov 29, 2012, 5:23:16 AM11/29/12
to moc...@googlegroups.com
Glad you fixed your problems.

Hoppy mocking then :)

Cheers,

-- Brice Dutheil

To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/bDhtMWUTM7wJ.
Reply all
Reply to author
Forward
0 new messages