I have written java application that makes socket connections with a legacy system.
How can I simulate the connection failure (Eg Socket connection timeout, read timeout, network failure), so that i can add necessary code based on the exception trace ?
Use a mock framework such as Mockito or EasyMock, mock a Socket object.
Look at the Javadoc for Socket and make your mocked object fail at some point with an Exception thrown by it in your unit tests.
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