我有这个方法public <T, R> R deepCopy(T source, R destination) { beanMapper.map(source, destination); return destination;}并想用不同的方法参数来模拟mock.deepCopy(classA(), classB()).thenReturn(classB());mock.deepCopy(classB(), classC()).thenReturn(classC());但得到类转换异常。
1 回答
![?](http://img1.sycdn.imooc.com/54584cd10001404b02200220-100-100.jpg)
30秒到达战场
TA贡献1828条经验 获得超6个赞
这个怎么样
doAnswer(invocation -> {
Object arg1 = invocation.getArguments()[0];
Object arg2 = invocation.getArguments()[1];
if(arg1 instanceof Integer && arg2 instanceof String)
return "something";
if(arg1 instanceof String && arg2 instanceof Boolean)
return false;
return false;
}).when(yourmock).deepCopy(any(), any());
现在,如果您使用参数 (1, "abcd") 传递 call 方法,则模拟将返回“某物”。如果你通过 ("abcd", true) 那么它返回 false
添加回答
举报
0/150
提交
取消