001: /*
002: * Copyright 2003-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.collections.buffer;
017:
018: import java.util.Collection;
019:
020: import junit.framework.Test;
021: import junit.framework.TestSuite;
022:
023: import org.apache.commons.collections.ArrayStack;
024: import org.apache.commons.collections.Buffer;
025: import org.apache.commons.collections.BufferUnderflowException;
026: import org.apache.commons.collections.Predicate;
027: import org.apache.commons.collections.collection.TestPredicatedCollection;
028:
029: /**
030: * Extension of {@link TestPredicatedCollection} for exercising the
031: * {@link PredicatedBuffer} implementation.
032: *
033: * @since Commons Collections 3.0
034: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
035: *
036: * @author Phil Steitz
037: */
038: public class TestPredicatedBuffer extends TestPredicatedCollection {
039:
040: public TestPredicatedBuffer(String testName) {
041: super (testName);
042: }
043:
044: public static Test suite() {
045: return new TestSuite(TestPredicatedBuffer.class);
046: }
047:
048: public static void main(String args[]) {
049: String[] testCaseName = { TestPredicatedBuffer.class.getName() };
050: junit.textui.TestRunner.main(testCaseName);
051: }
052:
053: //---------------------------------------------------------------
054:
055: protected Buffer decorateBuffer(Buffer buffer, Predicate predicate) {
056: return PredicatedBuffer.decorate(buffer, predicate);
057: }
058:
059: public Collection makeCollection() {
060: return decorateBuffer(new ArrayStack(), truePredicate);
061: }
062:
063: public Collection makeConfirmedCollection() {
064: return new ArrayStack();
065: }
066:
067: public Collection makeConfirmedFullCollection() {
068: ArrayStack list = new ArrayStack();
069: list.addAll(java.util.Arrays.asList(getFullElements()));
070: return list;
071: }
072:
073: //------------------------------------------------------------
074:
075: public Buffer makeTestBuffer() {
076: return decorateBuffer(new ArrayStack(), testPredicate);
077: }
078:
079: public void testGet() {
080: Buffer buffer = makeTestBuffer();
081: try {
082: Object o = buffer.get();
083: fail("Expecting BufferUnderflowException");
084: } catch (BufferUnderflowException ex) {
085: // expected
086: }
087: buffer.add("one");
088: buffer.add("two");
089: buffer.add("three");
090: assertEquals("Buffer get", buffer.get(), "three");
091: }
092:
093: public void testRemove() {
094: Buffer buffer = makeTestBuffer();
095: buffer.add("one");
096: assertEquals("Buffer get", buffer.remove(), "one");
097: try {
098: buffer.remove();
099: fail("Expecting BufferUnderflowException");
100: } catch (BufferUnderflowException ex) {
101: // expected
102: }
103: }
104:
105: public String getCompatibilityVersion() {
106: return "3.1";
107: }
108:
109: // public void testCreate() throws Exception {
110: // resetEmpty();
111: // writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.emptyCollection.version3.1.obj");
112: // resetFull();
113: // writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.fullCollection.version3.1.obj");
114: // }
115:
116: }
|