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.TestObjectPoolFactory;
021 import org.apache.commons.pool.ObjectPoolFactory;
022 import org.apache.commons.pool.PoolableObjectFactory;
023 import org.apache.commons.pool.MethodCallPoolableObjectFactory;
024 import junit.framework.Test;
025 import junit.framework.TestSuite;
026
027 /**
028 * Tests for {@link StackObjectPoolFactory}.
029 *
030 * @author Sandy McArthur
031 * @version $Revision: 774099 $ $Date: 2009-05-12 17:29:02 -0400 (Tue, 12 May 2009) $
032 */
033 public class TestStackObjectPoolFactory extends TestObjectPoolFactory {
034 public TestStackObjectPoolFactory(final String name) {
035 super(name);
036 }
037
038 public static Test suite() {
039 return new TestSuite(TestStackObjectPoolFactory.class);
040 }
041
042 protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws UnsupportedOperationException {
043 return new StackObjectPoolFactory(objectFactory);
044 }
045
046 public void testConstructors() throws Exception {
047 StackObjectPoolFactory factory = new StackObjectPoolFactory();
048 factory.createPool().close();
049
050
051 factory = new StackObjectPoolFactory(1);
052 StackObjectPool pool = (StackObjectPool)factory.createPool();
053 pool.close();
054
055
056 factory = new StackObjectPoolFactory(1, 1);
057 pool = (StackObjectPool)factory.createPool();
058 pool.close();
059
060
061 factory = new StackObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1);
062 pool = (StackObjectPool)factory.createPool();
063 Object a = pool.borrowObject();
064 Object b = pool.borrowObject();
065 pool.returnObject(a);
066 pool.returnObject(b);
067 assertEquals(1, pool.getNumIdle());
068 pool.close();
069 }
070 }