jeudi 28 juillet 2016

How do we unit test this lambda expression?

We have a REST end point (JAX-RS) that is invoked from the browser. We are passing around OutputStream so that we could have the browser display the result of the call.

Here is the method.

@Path("/mypath/{userId}")
@POST
public Response createUser(@PathParam("userId") final int userId ) {
    StreamingOutput stream = (outputStream) -> {
        User user = userHelper.findUser(userId);
        userHelper.updateUser(user,outputStream);
    };

    return Response.ok(stream).build();
}

Using Junit and Mockito, how do we verify if userHelper.findUser and userHelper.updateUser has been called ?

Basically we just want to verify the interactions.

Aucun commentaire:

Enregistrer un commentaire