001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.pool;
017:
018: import junit.framework.Test;
019: import junit.framework.TestCase;
020: import junit.framework.TestSuite;
021:
022: /**
023: * @author Rodney Waldhoff
024: * @version $Revision: 155430 $ $Date: 2005-02-26 08:13:28 -0500 (Sat, 26 Feb 2005) $
025: */
026: public class TestBaseKeyedObjectPool extends TestCase {
027: public TestBaseKeyedObjectPool(String testName) {
028: super (testName);
029: }
030:
031: public static Test suite() {
032: return new TestSuite(TestBaseKeyedObjectPool.class);
033: }
034:
035: // tests
036: public void testUnsupportedOperations() throws Exception {
037: KeyedObjectPool pool = new BaseKeyedObjectPool() {
038: public Object borrowObject(Object key) throws Exception {
039: return null;
040: }
041:
042: public void returnObject(Object key, Object obj)
043: throws Exception {
044: }
045:
046: public void invalidateObject(Object key, Object obj)
047: throws Exception {
048: }
049: };
050:
051: try {
052: pool.addObject("key");
053: fail("Expected UnsupportedOperationException");
054: } catch (UnsupportedOperationException e) {
055: // expected
056: }
057:
058: try {
059: pool.getNumIdle();
060: fail("Expected UnsupportedOperationException");
061: } catch (UnsupportedOperationException e) {
062: // expected
063: }
064:
065: try {
066: pool.getNumActive();
067: fail("Expected UnsupportedOperationException");
068: } catch (UnsupportedOperationException e) {
069: // expected
070: }
071:
072: try {
073: pool.clear();
074: fail("Expected UnsupportedOperationException");
075: } catch (UnsupportedOperationException e) {
076: // expected
077: }
078:
079: try {
080: pool.getNumIdle("key");
081: fail("Expected UnsupportedOperationException");
082: } catch (UnsupportedOperationException e) {
083: // expected
084: }
085:
086: try {
087: pool.getNumActive("key");
088: fail("Expected UnsupportedOperationException");
089: } catch (UnsupportedOperationException e) {
090: // expected
091: }
092:
093: try {
094: pool.clear("key");
095: fail("Expected UnsupportedOperationException");
096: } catch (UnsupportedOperationException e) {
097: // expected
098: }
099:
100: try {
101: pool.setFactory(null);
102: fail("Expected UnsupportedOperationException");
103: } catch (UnsupportedOperationException e) {
104: // expected
105: }
106:
107: pool.close(); // a no-op, probably should be remove
108:
109: }
110: }
|