In integration tests (JDK 6) I'm trying to catch all outgoing TCP connections and mock them. Looks like I should use java.net.Socket#setSocketImplFactory()
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 SocketImpl
class. I need this mostly because I want to let some connections to go out freely, without mocking. Can you suggest some manuals/guidelines/instructions about this problem?
Instead of mocking a Socket I would create a Socket service for the Socket to talk to. This can capture all the data written and reply in any manner you wish. It can be run in the same test and possibly in the same thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With