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  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  }