Reputation: 1
this is a sample code
when(someObject.someMethod(any(AbstractClass.class)).thenReturn(mockvalue);
in the above code, it isn't recognising the argument any(AbstractClass.class) and it calls the real method instead of returning the mock value.
Upvotes: 0
Views: 449
Reputation: 10652
I am sorry, but you are on the wrong track there.
any( SomeClass.class )
does NOT do what you believe it does. It especially does NOT check if the argument is a SomeClass
, see the Javadoc:
Any kind object, not necessary of the given class.
The class argument is provided only to avoid casting.
If you have a look at the Any class, you will see why:
public boolean matches(Object actual) {
return true;
}
So, ANY argument (as the name implies) will be accepted there. In your case, this means that IF the method someMethod
on that specific someObject
is called, it WILL return the mockvalue
, no matter what the actual argument is.
This implies that your problem is somewhere else entirely, for example ...
Hard to say without code. I would ask a new question but provide more code this time.
Upvotes: 1