Home > Enterprise >  Spock - wildcard in constructor
Spock - wildcard in constructor

Time:06-16

I have some class like this (for example in Kotlin but it has not to matter I think):

data class SomeClass(val a: String, val b: String, val c: String)

and then in the Spock unit test, I want to verify if the method taking SomeClass as an argument was called, but I want to verify only some fields, something like this:

1 * someService.doSomething(new SomeClass(_, _, "specificValue"))

As far as I know, I can't use wildcards in the constructor. So, is there any way to verify only some fields of the input object?

CodePudding user response:

Ok, I have an answer. The solution is:

1 * someService.doSomething({ SomeClass input ->
    input.c == "someSpecificValue"
})
  • Related