question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tweaks Matchers.any family matchers behavior

See original GitHub issue

This issue is a follow up of the work started in #141 by @pimterry. Also here’s an extract of a message on this thread of the mailing list :


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), null is a valid value
  • 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 family 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/create a symmetric isA family API that won’t allow any null arguments.


Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:32 (24 by maintainers)

github_iconTop GitHub Comments

1reaction
ChristianSchwarzcommented, Mar 30, 2016

My preference is to have the following matchers (option 1?):

  • <T> T any() that accepts anything including null. I associate “any” to the “anything” in my world that includes null-values and instances. It is compact and suitable for the most common cases.
  • <T> T anyObject() or <T> T notNull() reject null values opposite to any(). The name should indicate that null is rejected to avoid confusion about its behaviour.
  • <T> T isA(Class<? extends T>) reject null values and all values that are not a subtype of T, like instanceof.
  • all any*() and any(T) should be dropped cause they have different behaviour (as described before)
0reactions
raphwcommented, Jul 25, 2016

+1 i agree, lets try this for the RC.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are any... Matchers harmful? - Google Groups
So it seems to me that developers should generally avoid those any... Matchers, and prefer matchers that also check against null and wrong...
Read more >
Mockito Argument Matchers - any(), eq() - DigitalOcean
Mockito allows us to create mock objects and stub the behavior for our test cases. We usually mock the behavior using when() and...
Read more >
Mockito (Mockito 4.9.0 API) - javadoc.io
Let's verify some behaviour! 2. How about some stubbing? 3. Argument matchers 4. Verifying exact number of invocations / at least once /...
Read more >
Google Tweaks Phrase and Exact Match Keyword Behavior
Google Tweaks Phrase and Exact Match Keyword Behavior. Read our Blogs, Insights, Opinions & learn more about digital marketing ...
Read more >
Mockito Tutorial: An Overview of Different Types of Matchers
Matchers are like regex or wildcards where instead of a specific input (and or output), you specify a range/type of input/output based on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found