我有這個(gè)方法public <T, R> R deepCopy(T source, R destination) { beanMapper.map(source, destination); return destination;}并想用不同的方法參數(shù)來模擬mock.deepCopy(classA(), classB()).thenReturn(classB());mock.deepCopy(classB(), classC()).thenReturn(classC());但得到類轉(zhuǎn)換異常。
1 回答

30秒到達(dá)戰(zhàn)場(chǎng)
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
這個(gè)怎么樣
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());
現(xiàn)在,如果您使用參數(shù) (1, "abcd") 傳遞 call 方法,則模擬將返回“某物”。如果你通過 ("abcd", true) 那么它返回 false
添加回答
舉報(bào)
0/150
提交
取消