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.TestKeyedObjectPoolFactory;
21  import org.apache.commons.pool.KeyedObjectPoolFactory;
22  import org.apache.commons.pool.KeyedPoolableObjectFactory;
23  import junit.framework.Test;
24  import junit.framework.TestSuite;
25  
26  /**
27   * Tests for {@link StackKeyedObjectPoolFactory}.
28   *
29   * @author Sandy McArthur
30   * @version $Revision: 480413 $ $Date: 2006-11-29 00:16:05 -0500 (Wed, 29 Nov 2006) $
31   */
32  public class TestStackKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
33      public TestStackKeyedObjectPoolFactory(final String name) {
34          super(name);
35      }
36  
37      public static Test suite() {
38          return new TestSuite(TestStackKeyedObjectPoolFactory.class);
39      }
40  
41      protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
42          return new StackKeyedObjectPoolFactory(objectFactory);
43      }
44  
45      public void testConstructors() throws Exception {
46          StackKeyedObjectPoolFactory factory = new StackKeyedObjectPoolFactory();
47          factory.createPool().close();
48  
49          factory = new StackKeyedObjectPoolFactory(1);
50          StackKeyedObjectPool pool = (StackKeyedObjectPool)factory.createPool();
51          assertEquals(1,pool._maxSleeping);
52          pool.close();
53  
54          factory = new StackKeyedObjectPoolFactory(1, 2);
55          pool = (StackKeyedObjectPool)factory.createPool();
56          assertEquals(1,pool._maxSleeping);
57          assertEquals(2,pool._initSleepingCapacity);
58          pool.close();
59  
60          factory = new StackKeyedObjectPoolFactory(createObjectFactory());
61          pool = (StackKeyedObjectPool)factory.createPool();
62          pool.close();
63  
64          factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1);
65          pool = (StackKeyedObjectPool)factory.createPool();
66          assertEquals(1,pool._maxSleeping);
67          pool.close();
68  
69          factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1, 2);
70          pool = (StackKeyedObjectPool)factory.createPool();
71          assertEquals(1,pool._maxSleeping);
72          assertEquals(2,pool._initSleepingCapacity);
73          pool.close();
74  
75      }
76  }