我有一个正在测试的类需要在依赖类上存根调用。需要存根的代码如下所示:
public class A {
...
public void methodThatNeedsToBeStubbed(GenericClass genericClass){
...
}
}
这不编译:
when(mockA.methodThatNeedsToBeStubbed(any(GenericClass<SomeDifferentClass>))
我不确定如何使用泛型类作为参数?
答案 0 :(得分:2)
尝试将ArgumentCaptor
与@Captor
一起使用。
@Captor
ArgumentCaptor<GenericClass<SomeDifferentClass>> captor;
@Before
public void setup(){ MockitoAnnotations.initMocks(this));}
@Test
public void test(){
when(mockA.methodThatNeedsToBeStubbed(captor.capture()))...
}