responds With
fun <T : Any> respondsWith(responseType: Class<T>, configurer: Consumer<JavaResponseDefinitionBuilder<P, T>>)(source)
Configures a typed response for this stub.
Parameters
response Type
The Java Class of the response type.
configurer
A Consumer that configures a JavaResponseDefinitionBuilder.
Type Parameters
T
The type of the response body.
Configures a String response for this stub.
Shorthand for respondsWith(String.class, configurer).
Parameters
configurer
A Consumer that configures a JavaResponseDefinitionBuilder.
Configures a simple String response body for this stub with HTTP 200.
Shorthand for respondsWith(builder -> builder.body(body)):
mokksy.get("/hello").respondsWith("Hello, World!");Content copied to clipboard
Parameters
body
The response body string.
Configures a simple String response body with a custom HTTP status code.
Shorthand for respondsWith(builder -> builder.body(body).status(statusCode)):
mokksy.post("/items").respondsWith("{\"id\":42}", 201);Content copied to clipboard
Parameters
body
The response body string.
status Code
The HTTP status code, e.g. 201, 400.