In one of the Spock tests I see a strange condition in then block:
0 * someInstance._
What does it mean?
In one of the Spock tests I see a strange condition in then block:
0 * someInstance._
What does it mean?
_
is a wildcard, any object. See here to find how its exactly implemented and here for the docs. _
it's used for instance to check invocation of a method which argument does not matter, then it looks like:
1 * obj.method(1, _)
In this particular case it's checked if method method
on instance obj
was invoked exactly once with 1
as a first argument and anything as a second.
someInstance
is checked. In simple words. There was no interaction with someInstance
object. –
Exploration EDIT: My answer does not address the operators problem and refers to an unrelated problem. Correct answer can be seen above
_
is often used to denote private content/variables in languages such as Groovy/Javascript
that do now follow or provide visibility directives.
While you can still access them from outside of the class or instance the developer is trying to tell you that this variable is intended to be only used internally.
© 2022 - 2024 — McMap. All rights reserved.