TcpTransport implements Transport, ConnectionObserver { @Override public void connect() { asyncTcpSocketFactory.createSocketOnOutgoingConnection(socketAddress, new SocketFactory.SocketEstablishedCallback() { @Override public void onSocketEstablished(final SocketChannel socketChannel) { TcpTransport.this.socketChannel = socketChannel; publishingTransportObserver.connectionEstablished(); } }); } TcpTransport(final PublishingConnectionObserver publishingTransportObserver, final InetSocketAddress socketAddress,
                        final SocketFactory asyncTcpSocketFactory, final TransportConfig transportConfig); @Override void connect(); @Override void listen(); @Override void stopListening(); @Override ReadableByteChannel getReadableByteChannel(); @Override WritableByteChannel getWritableByteChannel(); @Override void killSocket(); @Override void close(); @Override boolean isConnected(); @Override void registerTransportObserver(final ConnectionObserver connectionObserver); @Override void unregisterTransportObserver(final ConnectionObserver connectionObserver); @Override void connectionEstablished(); @Override void connectionClosed();  }
@Test public void shouldCreateAnOutboundSocketWhenConnecting() throws Exception { final TcpTransport tcpTransport = new TcpTransport(publishingTransportObserver, socketAddress, socketFactory, new TransportConfigImpl(false)); mockery.checking(new Expectations() { { one(socketFactory).createSocketOnOutgoingConnection(with(socketAddress), with(any(SocketFactory.SocketEstablishedCallback.class))); } }); tcpTransport.connect(); }