title: How to mock an outgoing Socket connection?
body: <p>In integration tests (JDK 6) I'm trying to catch all outgoing TCP connections and mock them. Looks like I should use <a href="http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html#setSocketImplFactory(java.net.SocketImplFactory)" rel="noreferrer"><code>java.net.Socket#setSocketImplFactory()</code></a> method. Works fine at the moment, but I can't understand how I can get an access to original factory, in order to instantiate original JDK-provided <code>SocketImpl</code> class. I need this mostly because I want to let <em>some</em> connections to go out freely, without mocking. Can you suggest some manuals/guidelines/instructions about this problem?</p>