HandshakeCompletedListener implements ChannelFutureListener { @Override public void operationComplete( ChannelFuture future ) { if ( future.isSuccess() ) { BoltProtocol protocol = BoltProtocol.forChannel( future.channel() ); protocol.initializeChannel( userAgent, authToken, routingContext, connectionInitializedPromise ); } else { connectionInitializedPromise.setFailure( future.cause() ); } } HandshakeCompletedListener( String userAgent, AuthToken authToken,
                                       RoutingContext routingContext, ChannelPromise connectionInitializedPromise ); @Override void operationComplete( ChannelFuture future );  }
@Test void shouldFailConnectionInitializedPromiseWhenHandshakeFails() { ChannelPromise channelInitializedPromise = channel.newPromise(); HandshakeCompletedListener listener = new HandshakeCompletedListener( "user-agent", authToken(), RoutingContext.EMPTY, channelInitializedPromise ); ChannelPromise handshakeCompletedPromise = channel.newPromise(); IOException cause = new IOException( "Bad handshake" ); handshakeCompletedPromise.setFailure( cause ); listener.operationComplete( handshakeCompletedPromise ); Exception error = assertThrows( Exception.class, () -> await( channelInitializedPromise ) ); assertEquals( cause, error ); }