public void testCantResetFactoryWithActiveObjects() throws Exception {
    KeyedObjectPool pool = new StackKeyedObjectPool();
    pool.setFactory(new SimpleFactory());
    Object obj = pool.borrowObject("x");
    assertNotNull(obj);

    try {
      pool.setFactory(new SimpleFactory());
      fail("Expected IllegalStateException");
    } catch (IllegalStateException e) {
      // expected
    }
  }
 public void testCanResetFactoryWithoutActiveObjects() throws Exception {
   KeyedObjectPool pool = new StackKeyedObjectPool();
   {
     pool.setFactory(new SimpleFactory());
     Object obj = pool.borrowObject("x");
     assertNotNull(obj);
     pool.returnObject("x", obj);
   }
   {
     pool.setFactory(new SimpleFactory());
     Object obj = pool.borrowObject("x");
     assertNotNull(obj);
     pool.returnObject("x", obj);
   }
 }
 /**
  * Create a new <tt>KeyedPoolableConnectionFactory</tt>.
  *
  * @param cpds the ConnectionPoolDataSource from which to obtain PooledConnection's
  * @param pool the {*link ObjectPool} in which to pool those {*link Connection}s
  * @param validationQuery a query to use to {*link #validateObject validate} {*link Connection}s.
  *     Should return at least one row. May be <tt>null</tt>
  */
 public KeyedCPDSConnectionFactory(
     ConnectionPoolDataSource cpds, KeyedObjectPool pool, String validationQuery) {
   _cpds = cpds;
   _pool = pool;
   _pool.setFactory(this);
   _validationQuery = validationQuery;
 }
 public void testSetFactory() throws Exception {
   KeyedObjectPool pool = new StackKeyedObjectPool();
   try {
     pool.borrowObject("x");
     fail("Expected NoSuchElementException");
   } catch (NoSuchElementException e) {
     // expected
   }
   pool.setFactory(new SimpleFactory());
   Object obj = pool.borrowObject("x");
   assertNotNull(obj);
   pool.returnObject("x", obj);
 }