mlinhard / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Mockito.anySet() matches for non-Set parameters #279

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Mockito.doAnswer( new 
Answer<Class>(){...}).when(mock).setObject(Mockito.anySet());

should return null for all Objects which or not a Set.
(Answer return the class of the given Object)
but
mock.setObject("test");
returns String.class

For Details please see attached File.

What version of the product are you using? On what operating system?
Mockito 1.8.5

Original issue reported on code.google.com by his_madn...@gmx.de on 7 Sep 2011 at 9:18

Attachments:

GoogleCodeExporter commented 9 years ago
sry, should be
"for all Objects which ARE not a Set."

Original comment by his_madn...@gmx.de on 7 Sep 2011 at 9:22

GoogleCodeExporter commented 9 years ago
Not a defect.  You need to use isA( Set.class ), not anySet().  The Javadoc for 
anySet says 
" ... This method *don't do any type checks*, it is only there to avoid casting 
in your code. ... "

Original comment by dmwallace.nz on 17 Dec 2011 at 7:30

GoogleCodeExporter commented 9 years ago
Right, not a defect. I admit the name might be slightly misleading.

Original comment by szcze...@gmail.com on 17 Dec 2011 at 10:34

GoogleCodeExporter commented 9 years ago
The Javadoc has been updated in version 1.9.0 in order to clarify that as David 
quoted in his comment.

Original comment by brice.du...@gmail.com on 18 Dec 2011 at 2:47