I am using Mockito to mock some objects and test my WebSocket message sender service. The send method takes a org.springframework.web.socket.WebSocketSession
and a message, and returns a CompletableFuture
.
In the lambda passed to the thenAccept()
method of the CompletableFuture
, I verify that the session.sendMessage()
method has been called with the expected value :
WebSocketSession session = mockWebSocketSession();
TextMessage expectedMessage = new TextMessage("test text message");
sender.sendStringMessage(session, "test text message").thenAccept(nil -> {
try{ // this is what I am talking about
verify(session).sendMessage(expectedMessage);
}catch(IOException e){}
});
Since the sendMessage()
method throws an IOException
I am forced to add a useless try/catch block around the call on the inside the lambda. It is needlessly verbose.
How could I avoid it ?