// Path: src/main/java/com/github/mk23/jmxproxy/jmx/TimeoutRMISocketFactory.java
// public class TimeoutRMISocketFactory extends RMISocketFactory {
//     private static final Logger LOG = LoggerFactory.getLogger(TimeoutRMISocketFactory.class);
// 
//     private int timeout;
// 
//     /**
//      * <p>Default constructor.</p>
//      *
//      * Initializes the timeout to the specified value in milliseconds.
//      *
//      * @param timeout milliseconds to pass to Socket's connect() method.
//      */
//     public TimeoutRMISocketFactory(final int timeout) {
//         super();
// 
//         this.timeout = timeout;
//     }
// 
//     /**
//      * <p>Setter for timeout.</p>
//      *
//      * Resets the timeout to the specified milliseconds value.
//      *
//      * @param timeout milliseconds to pass to Socket's connect() method.
//      *
//      * @return Modified TimeoutRMISocketFactory for setter chaining.
//      */
//     public final TimeoutRMISocketFactory setTimeout(final int timeout) {
//         this.timeout = timeout;
//         return this;
//     }
// 
//     /** {@inheritDoc} */
//     @Override
//     public final Socket createSocket(final String host, final int port) throws IOException {
//         LOG.debug("creating new socket with " + timeout + "ms timeout");
// 
//         Socket socket = new Socket();
//         socket.connect(new InetSocketAddress(host, port), timeout);
// 
//         return socket;
//     }
// 
//     /** {@inheritDoc} */
//     @Override
//     public final ServerSocket createServerSocket(final int port) throws IOException {
//         return new ServerSocket(port);
//     }
// }


import com.github.mk23.jmxproxy.jmx.TimeoutRMISocketFactory;
import java.net.BindException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import static org.junit.Assert.assertNotNull;
package com.github.mk23.jmxproxy.jmx.tests;






public class TimeoutRMISocketFactoryTest {
    private final String validHost   = "localhost";
    private final String invalidHost = "192.0.2.1";

    private final int serverPort     = Integer.getInteger("com.sun.management.jmxremote.port");

    private final int connectTimeout = 500;

    @Rule public ExpectedException thrown = ExpectedException.none();
    @Rule public TestName name = new TestName();

    @Before
    public void printTestName() {
        System.out.println(" -> " + name.getMethodName());
    }

    @Test
    public void checkClientValidHostValidPort() throws Exception {
// Path: src/main/java/com/github/mk23/jmxproxy/jmx/TimeoutRMISocketFactory.java
// public class TimeoutRMISocketFactory extends RMISocketFactory {
//     private static final Logger LOG = LoggerFactory.getLogger(TimeoutRMISocketFactory.class);
// 
//     private int timeout;
// 
//     /**
//      * <p>Default constructor.</p>
//      *
//      * Initializes the timeout to the specified value in milliseconds.
//      *
//      * @param timeout milliseconds to pass to Socket's connect() method.
//      */
//     public TimeoutRMISocketFactory(final int timeout) {
//         super();
// 
//         this.timeout = timeout;
//     }
// 
//     /**
//      * <p>Setter for timeout.</p>
//      *
//      * Resets the timeout to the specified milliseconds value.
//      *
//      * @param timeout milliseconds to pass to Socket's connect() method.
//      *
//      * @return Modified TimeoutRMISocketFactory for setter chaining.
//      */
//     public final TimeoutRMISocketFactory setTimeout(final int timeout) {
//         this.timeout = timeout;
//         return this;
//     }
// 
//     /** {@inheritDoc} */
//     @Override
//     public final Socket createSocket(final String host, final int port) throws IOException {
//         LOG.debug("creating new socket with " + timeout + "ms timeout");
// 
//         Socket socket = new Socket();
//         socket.connect(new InetSocketAddress(host, port), timeout);
// 
//         return socket;
//     }
// 
//     /** {@inheritDoc} */
//     @Override
//     public final ServerSocket createServerSocket(final int port) throws IOException {
//         return new ServerSocket(port);
//     }
// }


// Path: src/test/java/com/github/mk23/jmxproxy/jmx/tests/TimeoutRMISocketFactoryTest.java
import com.github.mk23.jmxproxy.jmx.TimeoutRMISocketFactory;
import java.net.BindException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import static org.junit.Assert.assertNotNull;

package com.github.mk23.jmxproxy.jmx.tests;






public class TimeoutRMISocketFactoryTest {
    private final String validHost   = "localhost";
    private final String invalidHost = "192.0.2.1";

    private final int serverPort     = Integer.getInteger("com.sun.management.jmxremote.port");

    private final int connectTimeout = 500;

    @Rule public ExpectedException thrown = ExpectedException.none();
    @Rule public TestName name = new TestName();

    @Before
    public void printTestName() {
        System.out.println(" -> " + name.getMethodName());
    }

    @Test
    public void checkClientValidHostValidPort() throws Exception {
        final TimeoutRMISocketFactory sf = new TimeoutRMISocketFactory(connectTimeout);