* Verifies close contract - idle instances are destroyed, returning instances
* are destroyed, add/borrowObject throw IllegalStateException.
*/
public void testClose() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool pool = new StackObjectPool(factory);
pool.addObject(); // 0
pool.addObject(); // 1
pool.addObject(); // 2
Integer two = (Integer) pool.borrowObject();
assertEquals(2, two.intValue());
pool.close();
assertEquals(0, pool.getNumIdle());
assertEquals(1, pool.getNumActive());
List destroyed = factory.getDestroyed();
assertEquals(2, destroyed.size());
assertTrue(destroyed.contains(new Integer(0)));
assertTrue(destroyed.contains(new Integer(0)));
pool.returnObject(two);
assertTrue(destroyed.contains(two));
try {
pool.addObject();
fail("Expecting IllegalStateException");
} catch (IllegalStateException ex) {
// Expected
}
try {
pool.borrowObject();
fail("Expecting IllegalStateException");
} catch (IllegalStateException ex) {
// Expected
}
}