EDIT . Starting with Mockito 1.10.x, the generic types built into the class are now used by Mockito for deep stubs. i.e.
public interface A<T extends Observer & Comparable<? super T>> { List<? extends B> bList(); T observer(); } B b = deep_stubbed.bList().iterator().next();
Mockito is struggling to get the type information that the compiler uses, but when erasing is applied, mockito cannot do anything but return mock from Object .
Original : Well, this is more of a problem with generics than with Mockito. For generics, you should read what Angelika Langer wrote on them. And for the current topic, i.e. wildcards, read this section .
But for brevity, what you could use is another Mockito syntax that will help you in your current situation:
doReturn(interfaces).when(classAMock).getMyInterfaces();
Or using BDD aliases:
willReturn(interfaces).given(classAMock).getMyInterfaces();
However, you can write wrappers that are more versatile. This will help future developers work with the same third-party API.
As a side note: you should not scoff at a type that you do not own, this can lead to many errors and problems. Instead, you should have a shell. DAO and repositories, for example, represent such an idea; they will mock the DAO or repository interface, but not with JDBC / JPA / hibernate. There are many blog posts about this:
Brice Apr 11 '13 at 9:16 on 2013-04-11 09:16
source share