concept Groovy closure in category java

This is an excerpt from Manning's book Java Testing with Spock.
Closures are in many ways similar to methods. Unlike Java methods, they can be passed around as arguments to other methods or become partially evaluated instead of called directly. Java 8 also comes with lambda expressions, which serve as a stepping stone to functional programming concepts. If you’ve already worked with Java 8, Groovy closures will come naturally to you.
I briefly talked about closures in chapter 2. In their simplest form, you can think of them as anonymous Java functions with greater flexibility. If you’ve already worked with Java 8 and lambda expressions, Groovy closures will be familiar.
If you want to verify part of an object instance and not the whole instance, you can use Groovy closures in a similar way to stubs (as was shown in listing 6.8). The same syntax applies to mocks, as the following listing shows.
The last verification line in this listing checks only the vip field of the customer object. The other two fields (name and creditCard) can be anything, and the test will still pass. With the power of Groovy closures, you can check a mocked argument against any expression you can think of.
The previous section showed how to throw an exception in a stub by using a Groovy closure. I consider Groovy closures a powerful feature, even in the presence of Java 8, because the way Groovy closures are used in Spock is refreshing. In other mocking frameworks, such as Mockito, you need to learn separate syntax semantics for argument catchers, exception throwing, and dynamic responses. In Spock, all these are unified under Groovy closures.
Before I show any code, I’ll repeat the suggestion in chapter 2. If you don’t feel comfortable with Groovy closures (or Java 8 lambda expressions), feel free to skip this section and come back later. Closures can also be used with mocks, as you’ll see later in this chapter.