> isAString, isAnInt, isAList, isAListOf
> Do I miss something obvious?
Do you mean you'll like isA* methods mirroring the any hierarchy? ( I
think they can be syntethised with AditionalMathers using and(any*(),
isNotNull()), but I see they could be useful.
> I believe that in
> general,
> a check that does not accept nulls should be preferred over one that accepts
> null,
> because I believe software should avoid nulls wherever possible (Java8
> Optionals
> show that trend in general).
Here I dissent with you. I believe that, when both types of checks are
available, a check with accepth nulls should be used when null is a
valid value, and one that doe not when it is not.
I’d like to give additional info on this. The origin of these methods is they come from anything
i.e. anything matches, later for shortness and cast avoidance the aliases grew, but the API naming thus became inconsistent with what a human would expect. So this behavior is being changed in mockito 2 beta, to be precise here’s the status on these API in the version 2.0.5-beta :
any
, anyObject
, any(Class)
won’t check anything (at first they were just aliases for anything and for cast avoidance)anyX
like anyString
will check the arg is not null and that has the correct type
anyList
will check the argument is not null and a List
instance
anyListOf
(and the likes) at the moment are just aliases to their non generic counter part like anyList
Note this is work in progress (started here in #141), these new behavior can / will change in the beta phase. I’m especially wondering if the any
familly should allow null
and if not do a type check. For example with these matchers :
any
, anyObject
stay the same, they currently allow null
and don’t have to do type check anyway
any(Class)
currently allows null
and doesn’t do type check => allows null
and if not checks for the given type
any<Collection>Of
currently doesn’t allow null
and does a type check of the collection, not elements => allows null
, if not checks collection type, if not empty checks element type
Maybe extend the isA
family that won’t allow any null
arguments. Thoughts ?
— Brice
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
For more options, visit https://groups.google.com/d/optout.
Hey Francisco,
I agree, any
family should be consistent on null
s, that’s my proposition. By the way I took my previous message and created an issue there #194.
I kind of like anyNotNull
family, as you said it draws a clear behavior difference. There’s also the possibility to extend the notNull
family.
— Brice
Francisco Olarte.
This is slightly off topic, but if Mockito 2.x is going to break compatibility I'd like to see Mockito matchers have distinct names from Hamcrest matchers. My project uses both and dealing with the name clashes is a pain!
Jim Mayer
import static org.mockito.MockitoMatchers.somethingCool;...
orassertThat(result, Matchers.somethingCool(...));
import static org.hamcrest.Matchers.somethingCool;...
verify(something).myMethod(MockitoMatchers.somethingCool(...));
assertThat(result, Matchers.somethingCool(...));
verify(something).myMethod(MockitoMatchers.somethingCool(...));
Francisco Olarte.
anyObject()