@Test
public void shouldFireExceptionIfConnectEventCannotBeForwarded() throws Exception {

    setupPipelineToRunFireEventLaterInline();
    // setup the ctx to throw an exception when we attempt to send the connected event downstream
    IllegalStateException resolveFailureCause = new IllegalStateException("downstream event failed");
    doThrow(resolveFailureCause).when(ctx).sendDownstream(any(DownstreamChannelStateEvent.class));
    // initiate the connect request
    DefaultChannelFuture originalEventFuture = new DefaultChannelFuture(channel, false);
    ChannelStateEvent event = new DownstreamChannelStateEvent(
            channel,
            originalEventFuture,
            ChannelState.CONNECTED,
            createUnresolvedRemoteAddress()
    );
    handler.connectRequested(ctx, event);
    // firing the connect downstream should cause a "fireExceptionCaughtLater" call
    ArgumentCaptor<DefaultExceptionEvent> exceptionEventCaptor = ArgumentCaptor.forClass(DefaultExceptionEvent.class);
    verify(ctx).sendUpstream(exceptionEventCaptor.capture());
    DefaultExceptionEvent exceptionEvent = exceptionEventCaptor.getValue();
    assertThat(exceptionEvent.getCause(), Matchers.<Throwable>is(resolveFailureCause));
}