Mockito.when(connFactory.create(
Mockito.<HttpRoute>any(), Mockito.<ConnectionConfig>any())).thenReturn(conn);
final ConnectionRequest connRequest1 = mgr.requestConnection(route1, null);
final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn1);
Mockito.verify(connFactory, Mockito.times(1)).create(
Mockito.eq(route1), Mockito.<ConnectionConfig>any());
Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);
Assert.assertEquals(route1, mgr.getRoute());
Assert.assertEquals(null, mgr.getState());
final HttpHost target2 = new HttpHost("otherhost");
final HttpRoute route2 = new HttpRoute(target2);
final ConnectionRequest connRequest2 = mgr.requestConnection(route2, null);
final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn2);
Assert.assertFalse(conn2.isOpen());
Mockito.verify(conn).close();
Mockito.verify(connFactory, Mockito.times(1)).create(
Mockito.eq(route1), Mockito.<ConnectionConfig>any());
Mockito.verify(connFactory, Mockito.times(1)).create(