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.TestKeyedObjectPoolFactory;
021    import org.apache.commons.pool.KeyedObjectPoolFactory;
022    import org.apache.commons.pool.KeyedPoolableObjectFactory;
023    import junit.framework.Test;
024    import junit.framework.TestSuite;
025    
026    /**
027     * Tests for {@link StackKeyedObjectPoolFactory}.
028     *
029     * @author Sandy McArthur
030     * @version $Revision: 480413 $ $Date: 2006-11-29 00:16:05 -0500 (Wed, 29 Nov 2006) $
031     */
032    public class TestStackKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
033        public TestStackKeyedObjectPoolFactory(final String name) {
034            super(name);
035        }
036    
037        public static Test suite() {
038            return new TestSuite(TestStackKeyedObjectPoolFactory.class);
039        }
040    
041        protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
042            return new StackKeyedObjectPoolFactory(objectFactory);
043        }
044    
045        public void testConstructors() throws Exception {
046            StackKeyedObjectPoolFactory factory = new StackKeyedObjectPoolFactory();
047            factory.createPool().close();
048    
049            factory = new StackKeyedObjectPoolFactory(1);
050            StackKeyedObjectPool pool = (StackKeyedObjectPool)factory.createPool();
051            assertEquals(1,pool._maxSleeping);
052            pool.close();
053    
054            factory = new StackKeyedObjectPoolFactory(1, 2);
055            pool = (StackKeyedObjectPool)factory.createPool();
056            assertEquals(1,pool._maxSleeping);
057            assertEquals(2,pool._initSleepingCapacity);
058            pool.close();
059    
060            factory = new StackKeyedObjectPoolFactory(createObjectFactory());
061            pool = (StackKeyedObjectPool)factory.createPool();
062            pool.close();
063    
064            factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1);
065            pool = (StackKeyedObjectPool)factory.createPool();
066            assertEquals(1,pool._maxSleeping);
067            pool.close();
068    
069            factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1, 2);
070            pool = (StackKeyedObjectPool)factory.createPool();
071            assertEquals(1,pool._maxSleeping);
072            assertEquals(2,pool._initSleepingCapacity);
073            pool.close();
074    
075        }
076    }