### Question:
TransportSelectionHandler extends ByteToMessageDecoder { @Override public void exceptionCaught( ChannelHandlerContext ctx, Throwable cause ) throws Exception { try { if ( Exceptions.contains( cause, e -> e.getMessage().contains( "Connection reset by peer" ) ) ) { log.warn( "Fatal error occurred when initialising pipeline, " + "remote peer unexpectedly closed connection: %s", ctx.channel() ); } else { log.error( "Fatal error occurred when initialising pipeline: " + ctx.channel(), cause ); } } finally { ctx.close(); } } TransportSelectionHandler( BoltChannel boltChannel, SslContext sslCtx, boolean encryptionRequired, boolean isEncrypted, LogProvider logging,
            BoltProtocolFactory boltProtocolFactory ); @Override void exceptionCaught( ChannelHandlerContext ctx, Throwable cause );  }### Answer:
@Test public void shouldLogOnUnexpectedExceptionsAndClosesContext() throws Throwable { ChannelHandlerContext context = channelHandlerContextMock(); AssertableLogProvider logging = new AssertableLogProvider(); TransportSelectionHandler handler = new TransportSelectionHandler( null, null, false, false, logging, null ); Throwable cause = new Throwable( "Oh no!" ); handler.exceptionCaught( context, cause ); verify( context ).close(); logging.assertExactly( inLog( TransportSelectionHandler.class ) .error( equalTo( "Fatal error occurred when initialising pipeline: " + context.channel() ), sameInstance( cause ) ) ); }
@Test public void shouldLogConnectionResetErrorsAtWarningLevelAndClosesContext() throws Exception { ChannelHandlerContext context = channelHandlerContextMock(); AssertableLogProvider logging = new AssertableLogProvider(); TransportSelectionHandler handler = new TransportSelectionHandler( null, null, false, false, logging, null ); IOException connResetError = new IOException( "Connection reset by peer" ); handler.exceptionCaught( context, connResetError ); verify( context ).close(); logging.assertExactly( inLog( TransportSelectionHandler.class ) .warn( "Fatal error occurred when initialising pipeline, " + "remote peer unexpectedly closed connection: %s", context.channel() ) ); }