001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.pool.impl;
019    
020    import org.apache.commons.pool.KeyedObjectPoolFactory;
021    import org.apache.commons.pool.KeyedPoolableObjectFactory;
022    import org.apache.commons.pool.TestKeyedObjectPoolFactory;
023    
024    /**
025     * Tests for {@link StackKeyedObjectPoolFactory}.
026     *
027     * @author Sandy McArthur
028     * @version $Revision: 901944 $ $Date: 2010-01-21 17:27:04 -0700 (Thu, 21 Jan 2010) $
029     */
030    public class TestStackKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
031        public TestStackKeyedObjectPoolFactory(final String name) {
032            super(name);
033        }
034    
035        protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
036            return new StackKeyedObjectPoolFactory(objectFactory);
037        }
038    
039        public void testConstructors() throws Exception {
040            StackKeyedObjectPoolFactory factory = new StackKeyedObjectPoolFactory();
041            factory.createPool().close();
042    
043            factory = new StackKeyedObjectPoolFactory(1);
044            StackKeyedObjectPool pool = (StackKeyedObjectPool)factory.createPool();
045            assertEquals(1,pool._maxSleeping);
046            pool.close();
047    
048            factory = new StackKeyedObjectPoolFactory(1, 2);
049            pool = (StackKeyedObjectPool)factory.createPool();
050            assertEquals(1,pool._maxSleeping);
051            assertEquals(2,pool._initSleepingCapacity);
052            pool.close();
053    
054            factory = new StackKeyedObjectPoolFactory(createObjectFactory());
055            pool = (StackKeyedObjectPool)factory.createPool();
056            pool.close();
057    
058            factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1);
059            pool = (StackKeyedObjectPool)factory.createPool();
060            assertEquals(1,pool._maxSleeping);
061            pool.close();
062    
063            factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1, 2);
064            pool = (StackKeyedObjectPool)factory.createPool();
065            assertEquals(1,pool._maxSleeping);
066            assertEquals(2,pool._initSleepingCapacity);
067            pool.close();
068    
069        }
070    }