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):

mokksy.get(spec -> spec.path("/ping"))
.respondsWith(builder -> builder.body("Pong"));

mokksy.post(MyRequest.class, spec -> spec.path("/items"))
.respondsWith(MyResponse.class, builder -> builder
.body(new MyResponse("created"))
.status(201)
.header("Location", "/items/1"));

Type Parameters

P

The type of the request payload.

Functions

Link copied to clipboard

Configures a String response for this stub.

fun respondsWith(body: String)

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

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

Configures a typed response for this stub.

fun respondsWith(body: String, statusCode: Int)

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
fun respondsWithStatus(statusCode: Int)

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.