我正在使用mockito 1.9.5.我有以下代码:
public class ClassA {
public List<? extends MyInterface> getMyInterfaces() {
return null;
}
public static void testMock() {
List<MyInterface> interfaces = new ArrayList<>();
ClassA classAMock = mock(ClassA.class);
when(classAMock.getMyInterfaces()).thenReturn(interfaces);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个编译错误的thenReturn(interfaces)
说法:
"The method thenReturn(List<capture#1-of ? extends MyInterface>) in the type
OngoingStubbing<List<capture#1-of ? extends MyInterface>> is not applicable for the arguments
(List<MyInterface>)"
Run Code Online (Sandbox Code Playgroud)
但是,当我使用thenAnswer
mockito 的方法时,我没有得到错误.谁能告诉我发生了什么事?使用该thenReturn
方法时为什么会出现错误?当ClassA
第三方提供并且无法修改时,还有其他方法可以解决此问题吗?