### Question:
HostConnections { public NHttpClientConnection getConnection() { lock.lock(); try { while (!freeConnections.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Returning an existing free connection " + route); } NHttpClientConnection conn = freeConnections.get(0); long currentTime = System.currentTimeMillis(); long connectionInitTime = (Long) conn.getContext().getAttribute(PassThroughConstants. CONNECTION_INIT_TIME); long expiryTime = (Long) conn.getContext().getAttribute(PassThroughConstants. CONNECTION_EXPIRY_TIME); if (isMaximumLifeSpanExceeded(currentTime, connectionInitTime) || currentTime >= expiryTime ) { freeConnections.remove(conn); try { conn.shutdown(); } catch (IOException io) { log.error("Error occurred while shutting down connection." + io.getMessage(), io); } } else { freeConnections.remove(conn); busyConnections.add(conn); return conn; } } } finally { lock.unlock(); } return null; } HostConnections(HttpRoute route, int maxSize);  HostConnections(HttpRoute route, int maxSize, ConnectionTimeoutConfiguration
            connectionTimeoutConfiguration); NHttpClientConnection getConnection(); void release(NHttpClientConnection conn); void forget(NHttpClientConnection conn); void addConnection(NHttpClientConnection conn); synchronized void pendingConnectionSucceeded(); void pendingConnectionFailed(); HttpRoute getRoute(); boolean canHaveMoreConnections();  }### Answer:
@Test @UseDataProvider("data") public void testGetConnection(final int connectionIdleTime, final int maximumConnectionLifeSpan, final int connectionGraceTime) throws Exception { NHttpClientConnection nHttpClientConnection = Mockito.mock(NHttpClientConnection.class); List<NHttpClientConnection> freeConnections = new ArrayList<>(); freeConnections.add(nHttpClientConnection); ConnectionTimeoutConfiguration conf = new ConnectionTimeoutConfiguration(connectionIdleTime, maximumConnectionLifeSpan, connectionGraceTime); HostConnections hostConnections = new HostConnections(null, 1, conf); MemberModifier.field(HostConnections.class, "freeConnections").set(hostConnections, freeConnections); long currentTime = System.currentTimeMillis(); Mockito.when((nHttpClientConnection.getContext())).thenReturn(Mockito.mock(HttpContext.class)); Mockito.when((Long) nHttpClientConnection.getContext().getAttribute(PassThroughConstants.CONNECTION_INIT_TIME)) .thenReturn(0L); Mockito.when((Long) nHttpClientConnection.getContext().getAttribute(PassThroughConstants .CONNECTION_EXPIRY_TIME)) .thenReturn(currentTime); hostConnections.getConnection(); Mockito.verify(nHttpClientConnection, times(1)).shutdown(); Mockito.when((Long) nHttpClientConnection.getContext().getAttribute(PassThroughConstants.CONNECTION_INIT_TIME)) .thenReturn(currentTime); Mockito.when((Long) nHttpClientConnection.getContext().getAttribute(PassThroughConstants .CONNECTION_EXPIRY_TIME)) .thenReturn(0L); hostConnections.getConnection(); Mockito.verify(nHttpClientConnection, times(1)).shutdown(); }