### Question:
FailureMessageEncoder implements ResponseMessageEncoder<FailureMessage> { @Override public void encode( Neo4jPack.Packer packer, FailureMessage message ) throws IOException { if ( message instanceof FatalFailureMessage ) { log.debug( "Encoding a fatal failure message to send. Message: %s", message ); } encodeFailure( message, packer ); } FailureMessageEncoder( Log log ); @Override void encode( Neo4jPack.Packer packer, FailureMessage message );  }### Answer:
@Test void shouldEncodeFailureMessage() throws Throwable { Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); Log log = mock( Log.class ); FailureMessageEncoder encoder = new FailureMessageEncoder( log ); QueryResult.Record value = mock( QueryResult.Record.class ); when( value.fields() ).thenReturn( new AnyValue[0] ); encoder.encode( packer, new FailureMessage( Status.General.UnknownError, "I am an error message" ) ); verify( log, never() ).debug( anyString(), any( FailureMessage.class ) ); verify( packer ).packStructHeader( anyInt(), eq( FailureMessage.SIGNATURE ) ); verify( packer ).packMapHeader( 2 ); verify( packer ).pack( "code" ); verify( packer ).pack( "message" ); }
@Test void shouldLogErrorIfIsFatalError() throws Throwable { Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); Log log = mock( Log.class ); FailureMessageEncoder encoder = new FailureMessageEncoder( log ); QueryResult.Record value = mock( QueryResult.Record.class ); when( value.fields() ).thenReturn( new AnyValue[0] ); FatalFailureMessage message = new FatalFailureMessage( Status.General.UnknownError, "I am an error message" ); encoder.encode( packer, message ); verify( log ).debug( "Encoding a fatal failure message to send. Message: %s", message ); }