@Test
public void shouldFireExceptionIfAddressResolutionTaskFails() throws Exception {

    setupPipelineToRunFireEventLaterInline();
    // setup the address resolver to throw an exception
    final IllegalStateException resolveFailureCause = new IllegalStateException("simulate resolve failure");
    AddressResolverHandler.ResolvedAddressProvider failingResolver = new AddressResolverHandler.ResolvedAddressProvider() {
        @Override
        public InetSocketAddress createResolved(InetSocketAddress unresolvedAddress) throws Exception {
            throw resolveFailureCause;
        }
    };
    // fire a connect request with an unresolved address
    AddressResolverHandler failingHandler = new AddressResolverHandler(MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()), failingResolver);
    DefaultChannelFuture originalEventFuture = new DefaultChannelFuture(channel, false);
    ChannelStateEvent event = new DownstreamChannelStateEvent(
            channel,
            originalEventFuture,
            ChannelState.CONNECTED,
            createUnresolvedRemoteAddress()
    );
    failingHandler.connectRequested(ctx, event);
    // this 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));
}