Closed GoogleCodeExporter closed 8 years ago
Hi,
This is working as designed and I do believe it worked the same way in 1.7 (am I
wrong ? :)
You have to know that:
1. There is a difference between doReturn() and when(). when() actually invokes
the
method so any previous stubbing will be activated at the moment you do when().
This
is a trade off of the mocking syntax Mockito uses.
2. All argument matchers (like any()) always return nulls. Therefore in this
case:
setupSessionWorks();
setupSessionBroken();
invocation.getArguments()[0] is null
If you guys are doing some complex stubbing I suggest to use doReturn() as it
is a
tiny bit safer (but less readable...)
Original comment by szcze...@gmail.com
on 12 Sep 2009 at 6:04
Hi, I am able to reproduce it and I'm working on it.
Original comment by szcze...@gmail.com
on 15 Sep 2009 at 8:38
I see now. It's all because we changed the behavior of any() matcher in release
1.8.0
(see issue 73)
So, generally those nulls will be there. In order to avoid NPEs, either use
doReturn/doAnswer or use isA() matcher instead of any() matcher.
You're probably curious why the matcher matters, right? OK, so isA() matcher
does not
allow nulls. Calling any matcher creation methods (like any()) will return
null. This
all together makes mockito not use the previous stubbing when you call when()
for the
second time. It's hard to explain but those are hardcore gotchas pretty much
related
to how the mocking syntax is implemented.
Original comment by szcze...@gmail.com
on 15 Sep 2009 at 9:11
Original comment by szcze...@gmail.com
on 20 Oct 2009 at 6:47
Original issue reported on code.google.com by
leemil...@gmail.com
on 9 Sep 2009 at 11:03