如您所见,我尝试动态模拟响应。
underTest.getByTaskIds(taskIds)
将传递taskIds
的列表,在我将分别调用underTest.getByTaskId(taskId, channelId, false)
的方法内部。
但这行不通。
when:
def actual = underTest.getByTaskIds(taskIds)
then:
taskIds.forEach({ taskId ->
underTest.getByTaskId(taskId, channelId, false) >> mockResp.get(taskId)
})
actual.size() == expectedResultSize
where:
taskIds | mockResp | expectedResultSize
[] as Set<UUID> | [key: value] | 1
[UUID.randomUUID()] as Set<UUID> | [key: value] | 1
[UUID.randomUUID(), UUID.randomUUID()] as Set<UUID> | [key: value] | 2
class UnderTest:
void taskId(id){
do something
}
void taskIds(ids)->
{
this.taskId(id)
}