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.MethodCallPoolableObjectFactory; 021 import org.apache.commons.pool.ObjectPoolFactory; 022 import org.apache.commons.pool.PoolableObjectFactory; 023 import org.apache.commons.pool.TestObjectPoolFactory; 024 025 /** 026 * Tests for {@link StackObjectPoolFactory}. 027 * 028 * @author Sandy McArthur 029 * @version $Revision: 901944 $ $Date: 2010-01-21 17:27:04 -0700 (Thu, 21 Jan 2010) $ 030 */ 031 public class TestStackObjectPoolFactory extends TestObjectPoolFactory { 032 public TestStackObjectPoolFactory(final String name) { 033 super(name); 034 } 035 036 protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws UnsupportedOperationException { 037 return new StackObjectPoolFactory(objectFactory); 038 } 039 040 public void testConstructors() throws Exception { 041 StackObjectPoolFactory factory = new StackObjectPoolFactory(); 042 factory.createPool().close(); 043 044 045 factory = new StackObjectPoolFactory(1); 046 StackObjectPool pool = (StackObjectPool)factory.createPool(); 047 pool.close(); 048 049 050 factory = new StackObjectPoolFactory(1, 1); 051 pool = (StackObjectPool)factory.createPool(); 052 pool.close(); 053 054 055 factory = new StackObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1); 056 pool = (StackObjectPool)factory.createPool(); 057 Object a = pool.borrowObject(); 058 Object b = pool.borrowObject(); 059 pool.returnObject(a); 060 pool.returnObject(b); 061 assertEquals(1, pool.getNumIdle()); 062 pool.close(); 063 } 064 }