java - How can I make Mockito.verify ignore other type parameters? -
i have genericcreator, following method
<e extends entity> e create(e entity); i want assert method (where e = foo) called once. don't care if it's called other type parameter. following assertion not work me:
verify(genericcreator).create(any(foo.class)); because in following case:
foo foo = new foo(); bar bar = new bar(); genericcreator.create(foo); genericcreator.create(bar); it throws org.mockito.exceptions.verification.toomanyactualinvocations: genericcreator.create(<any>); wanted 1 time .... 2 times ... while in reality don't care .create(bar) call , don't want test fail because called. how can achieve this?
use isa matcher invocations care specific type.
http://site.mockito.org/mockito/docs/current/org/mockito/argumentmatchers.html#isa(java.lang.class)
the documentation any notes not check types -- it's there let avoid casting. thus, verifying accepts object of type -- why 2 calls instead of 1.
Comments
Post a Comment