Affects: 5.2.0.RELEASE
MockMvcResultHandlersDsl
has a handle(resultHandler: ResultHandler)
method. This method is useful, for example when the controller returns a StreamingResponseBody as the body value, in order to be able to call getAsyncResult()
.
ResultHandler is a functional interface. But since it's being used as the argument of a Kotlin method here, using it requires using the following code:
andDo {
handle(ResultHandler { it.asyncResult })
}
Instead of the more idiomatic
andDo {
handle { it.asyncResult }
}
This can of course be fixed by introducing my own extension function on MockMvcResultHandlersDsl
:
fun MockMvcResultHandlersDsl.handle(handler: (result: MvcResult) -> Unit) = handle(ResultHandler { handler(it) })
But I think I shouldn't have to do that, and handle()
should have taken a function as argument instead of a ResultHandler
in the first place.
It would be nice if a handle(handler: (result: MvcResult) -> Unit)
overloading method was added to MockMvcResultHandlersDsl
. And maybe the other one should be deprecated, too.
Comment From: sdeleuze
@jnizet Is this issue still relevant?
Comment From: jnizet
I can't remember where I used that, but yes, I think it's still relevant.
MockMvcResultHandlersDsl still has a handle()
function taking a ResultHandler
as argument.
Even though this function is probably used quite rarely, I would find it more idiomatic if the argument was a (MvcResult) -> Unit
. Adding an overload wouldn't break anything, and wouldn't be dangerous since ResultHandler
is explicitly annotated with @FunctionalInterface
(so adding an abstract method to the interface would break Java code).
Comment From: sdeleuze
At least with 1.4 it seems that SAM conversion allows to support andDo { handle { it.asyncResult } }
syntax natively, so I have just added a test case for it.