JavaBuildingStep

A Java-friendly wrapper around BuildingStep that exposes respondsWith, respondsWithStream, and respondsWithSseStream as instance methods accepting Consumer instead of Kotlin suspend lambdas.

Instances are returned by dev.mokksy.Mokksy's HTTP method stubs (get, post, etc.). Do not construct directly.

Example (Java):

StubHandle ping = mokksy.get(spec -> spec.path("/ping"))
.respondsWith(builder -> builder.body("Pong"));
assert ping.matchCount() == 0;

All response-definition methods return a StubHandle which exposes StubHandle.matchCount and StubHandle.name for verifying stub invocation after tests.

Type Parameters

P

The type of the request payload.

Functions

Link copied to clipboard

Configures a String response for this stub.

Configures a simple String response body for this stub with HTTP 200.

fun <T : Any> respondsWith(responseType: Class<T>, configurer: Consumer<JavaResponseDefinitionBuilder<P, T>>): StubHandle

Configures a typed response for this stub.

fun respondsWith(body: String, statusCode: Int): StubHandle

Configures a simple String response body with a custom HTTP status code.

Link copied to clipboard

Configures an SSE streaming response for this stub with ServerSentEventMetadata<String> chunks.

Configures a typed SSE streaming response for this stub.

Link copied to clipboard

Associates this stub with a body-free response carrying only an HTTP status code.

Link copied to clipboard

Configures a String streaming response for this stub.

Configures a typed streaming response for this stub.