InitMessageEncoder implements MessageEncoder { @Override public void encode( Message message, ValuePacker packer ) throws IOException { checkArgument( message, InitMessage.class ); InitMessage initMessage = (InitMessage) message; packer.packStructHeader( 2, initMessage.signature() ); packer.pack( initMessage.userAgent() ); packer.pack( initMessage.authToken() ); }  @Override void encode( Message message, ValuePacker packer );  }
@Test void shouldEncodeInitMessage() throws Exception { Map<String,Value> authToken = new HashMap<>(); authToken.put( "username", value( "bob" ) ); authToken.put( "password", value( "secret" ) ); encoder.encode( new InitMessage( "MyDriver", authToken ), packer ); InOrder order = inOrder( packer ); order.verify( packer ).packStructHeader( 2, InitMessage.SIGNATURE ); order.verify( packer ).pack( "MyDriver" ); order.verify( packer ).pack( authToken ); }
@Test void shouldFailToEncodeWrongMessage() { assertThrows( IllegalArgumentException.class, () -> encoder.encode( PullAllMessage.PULL_ALL, packer ) ); }