假设我有:
class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}
和
class Conflicts extends RuntimeException {
List<Conflict> conflicts = new ArrayList<>()
Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}
在Spock中,我通常使用spread operator检查异常消息:
def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]
在Groovy中,有没有办法以类似简洁的方式检查startsWith
,like
和其他操作?
答案 0 :(得分:1)
您可以使用every
:
def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }