An answewr on this thread suggested using anyCollectionOf() however I cannot get it to work
Mockito: Verifying with generic parameters
I have a Generic Class for holding two “versions” of the same object for comparison purposes
public class ChangedVO<T> {
private T before;
private T after;
/*** Constructors ***/
public ChangedVO() {}
public ChangedVO(T before, T after) {
this.before = before;
this.after = after;
}
/*** Getters & setters ***/
...
}
Now in my UnitTest the following code “does” work…
verify(emailService, never()).sendBookChangesEmail(Matchers.<List<ChangedVO<BookVO>>>any());
…however I’m interested to know how the same thing can be achieved using anyCollectionOf() ?
Interesting use of Mockito with generics. The only way I think you can use
anyListOf()in this situation is by typingInstead of passing a class instance you pass it null. This is not how the documentation says you shoud use
anyListOf()but in this specific situation it seems to work.The problem is generic type erasure in Java which makes that you can not differentiate between an instance of
during runtime and therefore there is no way you can create anything that statically conforms to