ServerMessageValidator implements MessageValidator<ServerProtocol> { @Override public ServerProtocol cast(Message message) { return message.getServer(); } @Inject  ServerMessageValidator(); @Override boolean isValid(Message message); @Override ServerProtocol cast(Message message); List<InvalidServerData> getInvalidServerData();  }
@Test public void shouldProperlyCastMessageIntoServer() throws Exception { when(mockMessage.getServer()).thenReturn(mockServerProtocol); ServerProtocol serverProtocol = serverMessageValidator.cast(mockMessage); assertThat(serverProtocol).isNotNull(); assertThat(serverProtocol).isInstanceOf(ServerProtocol.class); verify(mockMessage, times(1)).getServer(); verifyNoMoreInteractions(mockMessage); }