Hi,
Erratum in my previous post : "And I'm pretty sure Johan *didn't do it* differently."
Without going into details let's look at this code written using with Mockito :
given(mock.doSomethingWith(eq("A"), longThat(...)).thenReturn("C");
Which is roughly equivalent to :
(***** NEVER use a reference to OngoingStubbing in real test code, it might lead to wrong test code *****)
String aString = eq("A");
Long aLong = longThat(...);
String variableThatGiveReturnType = mock.doSomethingWith(aString, aLong);
BDDOngoingStubbing<String> ongoingStubbing = given(variableThatGiveReturnType);
ongoingStubbing.thenReturn("C");
The stubbing is clearly not finished until the last call thenReturn is completed, right.
Don't you see the missing link between all those line to actually achieve the stubbing in a fluent way ? ;)
Dependening on how you do that, if you don't synchronize this block you won't be able to achieve any correct stubbing, otherwise concurrent access anywhere in this block will garble things in the mock internals.
And if you add the fact that the mock might be already used, with it's own concurrent code to use the answers, you end up in with completely messed up internal states.
Anyway, always stub before using mocks concurrently.
Cheers,
--
Brice