IBConnectionUtil { public IBSocket getIBSocket() { if (ibSocket == null) { IBConnectionInfo info = new IBConnectionInfo(host, port, clientId); ibSocket = IBConnectionRegistry.getIBSocket(info); } return ibSocket; } IBConnectionUtil(String host, int port, int clientId); IBSocket getIBSocket();  }
@Test public void testGetIbSocket() { String host = "myhost"; int port = 123; int clientId = 999; IBConnectionUtil util = new IBConnectionUtil(host, port, clientId); assertEquals( host, util.host ); assertEquals(port, util.port ); assertEquals( clientId, util.clientId ); assertNull( util.ibSocket ); IBSocket socket = util.getIBSocket(); assertNotNull( socket ); assertEquals( host, socket.getConnection().getHost() ); assertEquals( port, socket.getConnection().getPort() ); assertEquals( clientId, socket.getConnection().getClientId() ); IBSocket secondSocket = util.getIBSocket(); assertTrue( socket == secondSocket ); }