Now, i hava a method defined like below:
public final class StringUtils {
public static String format(String format, Object... args) {
// do sth.
}
}
and my spock tests code like this:
class StringUtilsTests extends Specification {
def "format: normal"() {
given:
def messageFormat = "test {}, {}"
def args = ["message", "format"]
when:
def message = StringUtils.format(messageFormat, "message", "format")
def message2 = StringUtils.format(messageFormat, args)
def message3 = StringUtils.format(messageFormat, args as Object[])
def message4 = StringUtils.format(messageFormat, args.flatten)
then:
message == "test message, format"
message2 == "test message, format"
message3 == "test message, format"
message4 == "test message, format"
}
}
All of result is test ["message", "format"], {}
so, how to call a java vararg method with spock?
New contributor
Moore Ma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.