Argument Matchers and null arguments

1,378 views
Skip to first unread message

PhilWills

unread,
Jun 3, 2008, 10:50:16 AM6/3/08
to mockito
When you use a stub, or verify that uses an anyX matcher, it does not
match against null. While this is semantically correct, when I use an
anyX matcher, I'm indicating that that argument isn't of interest to
me in this particular test and hence I'm not interested whether or not
it's null.

Is this a deliberate design decision and if so can you explain it for
me please?

Thanks,

Phil Wills

szczepiq

unread,
Jun 3, 2008, 12:16:23 PM6/3/08
to moc...@googlegroups.com
Hi,

anyX() matchers work exactly the same as in EasyMock. I considered
making anyX() also lenient about nulls (and even suggested that to EM
guys) but I got convinced to keep it (as you say) semantically
correct.

I'm changing my mind, though. I agree that anyX() communicates "I
don't care about it". If I care about having the argument being **not
null** I should write isNotNull() which is explicit! That's why I'd
like to change the way anyX() matchers work - to allow nulls as a
valid **any** things. Any comments from other users? Also, I will add
isNotNull() matcher to complete the implementation change.

Thanks for pointing that out.
Cheers,
Szczepan Faber

Kris

unread,
Jun 23, 2008, 10:23:37 AM6/23/08
to mockito
> I'm changing my mind, though. I agree that anyX() communicates "I
> don't care about it". If I care about having the argument being **not
> null** I should write isNotNull() which is explicit! That's why I'd
> like to change the way anyX() matchers work - to allow nulls as a
> valid **any** things. Any comments from other users? Also, I will add
> isNotNull() matcher to complete the implementation change.

I agree. anyX() should also match null.

john...@fansentertainment.com

unread,
Jun 13, 2017, 12:18:54 PM6/13/17
to mockito, kris.va...@gmail.com
I like this idea too :  anyX() should also match null
Reply all
Reply to author
Forward
0 new messages