onResponseReady

Registers a listener that is invoked when a matched stub is about to send its response.

The listener fires after response headers and status have been applied, but before the response body is written. This allows test assertions on shared state (e.g., semaphore permits) at the exact moment a response is ready to be sent on the wire.

Example:

mokksyServer.onResponseReady { request, response ->
semaphore.availablePermits shouldBe 0
}

Only a single listener may be registered. Subsequent calls replace the previous one.

Parameters

listener

A suspend lambda receiving the RecordedRequest and the AbstractResponseDefinition about to be sent.

See also

For non-suspend usage from Java or Kotlin.