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.ObjectPool;
021    import org.apache.commons.pool.PoolableObjectFactory;
022    import org.apache.commons.pool.TestBaseObjectPool;
023    
024    /**
025     * @author Rodney Waldhoff
026     * @author Sandy McArthur
027     * @version $Revision: 901944 $ $Date: 2010-01-21 17:27:04 -0700 (Thu, 21 Jan 2010) $
028     */
029    public class TestSoftReferenceObjectPool extends TestBaseObjectPool {
030        public TestSoftReferenceObjectPool(String testName) {
031            super(testName);
032        }
033    
034        protected ObjectPool makeEmptyPool(int cap) {
035            return new SoftReferenceObjectPool(
036                new PoolableObjectFactory()  {
037                    int counter = 0;
038                    public Object makeObject() { return String.valueOf(counter++); }
039                    public void destroyObject(Object obj) { }
040                    public boolean validateObject(Object obj) { return true; }
041                    public void activateObject(Object obj) { }
042                    public void passivateObject(Object obj) { }
043                }
044                );
045        }
046    
047        protected ObjectPool makeEmptyPool(final PoolableObjectFactory factory) {
048            return new SoftReferenceObjectPool(factory);
049        }
050    
051        protected Object getNthObject(int n) {
052            return String.valueOf(n);
053        }
054    
055        protected boolean isLifo() {
056            return false;
057        }
058    
059        protected boolean isFifo() {
060            return false;
061        }
062    
063    }