Link Search Menu Expand Document

How to test a route action

You can write a unit test of the route action. Methods mock, whenever and verify are provided by mockito-kotlin

private val request: Request = mock()
private val response: Response = mock()

fun `eating a daikon`() {

    EatingRouteAction().handle(request, response)

    verify(response).write("You are eating a daikon")

class EatingRouteAction : RouteAction {
    override fun handle(request: Request, response: Response) {
        response.write("You are eating a ${request.param("food")}")

An Open Source Project