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;
019    
020    import junit.framework.TestCase;
021    
022    /**
023     * Tests for all {@link KeyedObjectPoolFactory}s.
024     *
025     * @author Sandy McArthur
026     * @version $Revision: 480413 $ $Date: 2006-11-28 22:16:05 -0700 (Tue, 28 Nov 2006) $
027     */
028    public abstract class TestKeyedObjectPoolFactory extends TestCase {
029        protected TestKeyedObjectPoolFactory(final String name) {
030            super(name);
031        }
032    
033        /**
034         * @throws UnsupportedOperationException when this is unsupported by this KeyedPoolableObjectFactory type.
035         */
036        protected KeyedObjectPoolFactory makeFactory() throws UnsupportedOperationException {
037            return makeFactory(createObjectFactory());
038        }
039    
040        /**
041         * @throws UnsupportedOperationException when this is unsupported by this KeyedPoolableObjectFactory type.
042         */
043        protected abstract KeyedObjectPoolFactory makeFactory(KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException;
044    
045        protected static KeyedPoolableObjectFactory createObjectFactory() {
046            return PoolUtils.adapt(new MethodCallPoolableObjectFactory());
047        }
048    
049        public void testCreatePool() throws Exception {
050            final KeyedObjectPoolFactory factory;
051            try {
052                factory = makeFactory();
053            } catch (UnsupportedOperationException uoe) {
054                return;
055            }
056            final KeyedObjectPool pool = factory.createPool();
057            pool.close();
058        }
059    
060        public void testToString() {
061            final KeyedObjectPoolFactory factory;
062            try {
063                factory = makeFactory();
064            } catch (UnsupportedOperationException uoe) {
065                return;
066            }
067            factory.toString();
068        }
069    }