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
28
29
30
31
32
33 public class TestStackObjectPoolFactory extends TestObjectPoolFactory {
34 public TestStackObjectPoolFactory(final String name) {
35 super(name);
36 }
37
38 public static Test suite() {
39 return new TestSuite(TestStackObjectPoolFactory.class);
40 }
41
42 protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws UnsupportedOperationException {
43 return new StackObjectPoolFactory(objectFactory);
44 }
45
46 public void testConstructors() throws Exception {
47 StackObjectPoolFactory factory = new StackObjectPoolFactory();
48 factory.createPool().close();
49
50
51 factory = new StackObjectPoolFactory(1);
52 StackObjectPool pool = (StackObjectPool)factory.createPool();
53 pool.close();
54
55
56 factory = new StackObjectPoolFactory(1, 1);
57 pool = (StackObjectPool)factory.createPool();
58 pool.close();
59
60
61 factory = new StackObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1);
62 pool = (StackObjectPool)factory.createPool();
63 Object a = pool.borrowObject();
64 Object b = pool.borrowObject();
65 pool.returnObject(a);
66 pool.returnObject(b);
67 assertEquals(1, pool.getNumIdle());
68 pool.close();
69 }
70 }