對于我的測試,我需要模擬我的光標(biāo)的 hasNext() 方法。但是,要完全測試我的代碼,我需要 250 次迭代才能發(fā)送到 bulkRequest。因此,我最后需要 250 x true 和 1 x false。我創(chuàng)建了一個布爾數(shù)組,里面有 250 個真和 1 個假我得到了什么@Mockprivate Cursor<Record> cursor;public void myTest(){ when(cursor.hasNext()).thenReturn(true, false);}但現(xiàn)在我需要 250 個光標(biāo)條件,所以我創(chuàng)建了一個布爾數(shù)組,但顯然它無法編譯final boolean[] cursorsResponses = fillCursors();when(cursor.hasNext()).thenReturn(cursorsResponses);
1 回答

慕碼人8056858
TA貢獻1803條經(jīng)驗 獲得超6個贊
所以在你的情況下:
when(cursor.hasNext()).thenAnswer(new Answer() {
private int count = 0;
public Object answer(InvocationOnMock invocation) {
return (count++ < 250);
}
});
添加回答
舉報
0/150
提交
取消