1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * Tests for {@link StackObjectPoolFactory}.
29   *
30   * @author Sandy McArthur
31   * @version $Revision: 774099 $ $Date: 2009-05-12 17:29:02 -0400 (Tue, 12 May 2009) $
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  }