RunMessageEncoder implements MessageEncoder { @Override public void encode( Message message, ValuePacker packer ) throws IOException { checkArgument( message, RunMessage.class ); RunMessage runMessage = (RunMessage) message; packer.packStructHeader( 2, runMessage.signature() ); packer.pack( runMessage.query() ); packer.pack( runMessage.parameters() ); }  @Override void encode( Message message, ValuePacker packer );  }
@Test void shouldEncodeRunMessage() throws Exception { Map<String,Value> params = singletonMap( "answer", value( 42 ) ); encoder.encode( new RunMessage( "RETURN $answer", params ), packer ); InOrder order = inOrder( packer ); order.verify( packer ).packStructHeader( 2, RunMessage.SIGNATURE ); order.verify( packer ).pack( "RETURN $answer" ); order.verify( packer ).pack( params ); }
@Test void shouldFailToEncodeWrongMessage() { assertThrows( IllegalArgumentException.class, () -> encoder.encode( DiscardAllMessage.DISCARD_ALL, packer ) ); }