ChannelHandler { String toServerMessage(V message) { if (message == null) throw new Error("message must not be null"); if (!serverMessageClass.equals(message.getClass())) { throw new Error(Strings.format("message class does not match, expected={}, actual={}", serverMessageClass.getCanonicalName(), message.getClass().getCanonicalName())); } serverMessageValidator.validate(message, false); return serverMessageWriter.toJSONString(message); } ChannelHandler(Class<T> clientMessageClass, Class<V> serverMessageClass, ChannelListener<T, V> listener);   }
@Test void toServerMessage() { var message = new TestWebSocketMessage(); message.message = "value"; assertThat(handler.toServerMessage(message)).isEqualTo("{\"message\":\"value\"}"); assertThatThrownBy(() -> handler.toServerMessage(new MismatchTestMessage())) .isInstanceOf(Error.class) .hasMessageContaining("message class does not match"); }