我想为以下类似方法编写单元测试。我的主要问题是changeSets对象的结构。
Mockito.doReturn([changeSets:[item:[[author: 'author', msg: 'msg']]]])
如何在doReturn中准备正确的对象?实体必须具有长度,而不是上述的size()。整个对象的className是什么?
@NonCPS
def getChangeString() {
MAX_MSG_LEN = 10
def changeString = ""
echo "Gathering SCM changes"
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
changeString += " - ${truncated_msg} [${entry.author}]\n"
}
}
if (!changeString) {
changeString = " - No new changes"
}
return changeString
}
如何进入第二循环?