import io.vertx.core.Vertx
import io.vertx.core.http.RequestOptions
import spock.lang.Specification
import spock.util.concurrent.AsyncConditions
 
class AsyncExampleSpec extends Specification {
    def "Async request for google.com should return proper page content"() {
        given: "An async HTTP client"
            def client = Vertx.vertx().createHttpClient()
        and: "Some HTTP request options"
            def opts = new RequestOptions()
            opts.ssl = true
            opts.port = 443
            opts.host = 'www.google.com'
            opts.URI = '/'
        and: "An instance of AsyncConditions"
            def async = new AsyncConditions(1)  // Create the instance of AsyncConditions which will expect 1 async operation
 
        when: "The google.com web site is requested"
            client.getNow(opts, { res ->        // This Closure is handling the async results from the HTTP request
                async.evaluate {                // The async.evaluate closure resolves the AsyncCondition
                    res.statusCode() == 200
                }
            })
 
        then: "Expect the result to be completed in the specified time"
            async.await(5.5)                    // If the AsyncCondition is not resolved in 5.5 seconds, the test fails.
    }
}

testingjavaspringspock