code: @Test public void testLeaseReleaseStateful() throws Exception {
    LocalRoutePool pool=new LocalRoutePool();
    HttpConnection conn1=Mockito.mock(HttpConnection.class);
    LocalPoolEntry entry1=pool.add(conn1);
    HttpConnection conn2=Mockito.mock(HttpConnection.class);
    LocalPoolEntry entry2=pool.add(conn2);
    HttpConnection conn3=Mockito.mock(HttpConnection.class);
    LocalPoolEntry entry3=pool.add(conn3);
    Assert.assertNotNull(entry1);
    Assert.assertNotNull(entry2);
    Assert.assertNotNull(entry3);
    Assert.assertEquals(3,pool.getAllocatedCount());
    Assert.assertEquals(0,pool.getAvailableCount());
    Assert.assertEquals(3,pool.getLeasedCount());
    Assert.assertEquals(0,pool.getPendingCount());
    entry2.setState(Boolean.FALSE);
    pool.free(entry1,true);
    pool.free(entry2,true);
    pool.free(entry3,true);
    Assert.assertEquals(entry2,pool.getFree(Boolean.FALSE));
    Assert.assertEquals(entry1,pool.getFree(Boolean.FALSE));
    Assert.assertEquals(entry3,pool.getFree(null));
    Assert.assertEquals(null,pool.getFree(null));
    entry1.setState(Boolean.TRUE);
    entry2.setState(Boolean.FALSE);
    entry3.setState(Boolean.TRUE);
    pool.free(entry1,true);
    pool.free(entry2,true);
    pool.free(entry3,true);
    Assert.assertEquals(null,pool.getFree(null));
    Assert.assertEquals(entry2,pool.getFree(Boolean.FALSE));
    Assert.assertEquals(null,pool.getFree(Boolean.FALSE));
    Assert.assertEquals(entry1,pool.getFree(Boolean.TRUE));
    Assert.assertEquals(entry3,pool.getFree(Boolean.TRUE));
    Assert.assertEquals(null,pool.getFree(Boolean.TRUE));
  }
  