Connection { public void open() throws ConnectionException { if (!isConnected()) { try { socket = createSocket(); socket.setReuseAddress(true); socket.setKeepAlive(true); socket.setTcpNoDelay(true); socket.setSoLinger(true, 0); socket.connect(getInetSocketAddress(), timeout); socket.setSoTimeout(socketTimeout); } catch (IOException ex) { throw new ConnectionException(ex); } } } Connection();  Connection(final String host);  Connection(final String host, final int port);  Connection(final String host, final int port, final int timeout, final int socketTimeout); int getTimeout(); int getSocketTimeout(); String getHost(); int getPort(); boolean isConnected(); void open(); void close(); RedisStreamWriter getStreamWriter(); RedisStreamReader getStreamReader(); final static int DEFAULT_TIMEOUT; final static int DEFAULT_SOCKET_TIMEOUT; static final String DEFAULT_HOST; static final int DEFAULT_PORT; }
@Test public void open() throws ConnectionException, IOException { doReturn(false).when(connection).isConnected(); doReturn(socket).when(connection).createSocket(); connection.open(); assertNotNull(connection.getStreamReader()); assertNotNull(connection.getStreamWriter()); verify(socket).setSoTimeout(Connection.DEFAULT_SOCKET_TIMEOUT); assertEquals(connection.getHost(), Connection.DEFAULT_HOST); assertEquals(connection.getPort(), Connection.DEFAULT_PORT); assertEquals(connection.getSocketTimeout(), Connection.DEFAULT_SOCKET_TIMEOUT); assertEquals(connection.getTimeout(), Connection.DEFAULT_TIMEOUT); }