1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.pool.impl;
19
20 import org.apache.commons.pool.TestObjectPoolFactory;
21 import org.apache.commons.pool.ObjectPoolFactory;
22 import org.apache.commons.pool.PoolableObjectFactory;
23 import org.apache.commons.pool.MethodCallPoolableObjectFactory;
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import java.util.NoSuchElementException;
28
29 /***
30 * Tests for {@link StackObjectPoolFactory}.
31 *
32 * @author Sandy McArthur
33 * @version $Revision: 480413 $ $Date: 2006-11-28 22:16:05 -0700 (Tue, 28 Nov 2006) $
34 */
35 public class TestStackObjectPoolFactory extends TestObjectPoolFactory {
36 public TestStackObjectPoolFactory(final String name) {
37 super(name);
38 }
39
40 public static Test suite() {
41 return new TestSuite(TestStackObjectPoolFactory.class);
42 }
43
44 protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws UnsupportedOperationException {
45 return new StackObjectPoolFactory(objectFactory);
46 }
47
48 public void testConstructors() throws Exception {
49 StackObjectPoolFactory factory = new StackObjectPoolFactory();
50 factory.createPool().close();
51
52
53 factory = new StackObjectPoolFactory(1);
54 StackObjectPool pool = (StackObjectPool)factory.createPool();
55 pool.close();
56
57
58 factory = new StackObjectPoolFactory(1, 1);
59 pool = (StackObjectPool)factory.createPool();
60 pool.close();
61
62
63 factory = new StackObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1);
64 pool = (StackObjectPool)factory.createPool();
65 Object a = pool.borrowObject();
66 Object b = pool.borrowObject();
67 pool.returnObject(a);
68 pool.returnObject(b);
69 assertEquals(1, pool.getNumIdle());
70 pool.close();
71 }
72 }