001: /*
002: * Copyright 2001-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;
017:
018: import java.util.Arrays;
019: import java.util.Collection;
020:
021: import junit.framework.Test;
022:
023: /**
024: * Runs tests against a full BoundedFifoBuffer, since many of the algorithms
025: * differ depending on whether the fifo is full or not.
026: *
027: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
028: *
029: * @author Unknown
030: */
031: public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer {
032:
033: public TestBoundedFifoBuffer2(String n) {
034: super (n);
035: }
036:
037: public static Test suite() {
038: return BulkTest.makeSuite(TestBoundedFifoBuffer2.class);
039: }
040:
041: /**
042: * Returns a BoundedFifoBuffer that's filled to capacity.
043: * Any attempt to add to the returned buffer will result in a
044: * BufferOverflowException.
045: *
046: * @return a full BoundedFifoBuffer
047: */
048: public Collection makeFullCollection() {
049: return new BoundedFifoBuffer(Arrays.asList(getFullElements()));
050: }
051:
052: /**
053: * Overridden to skip the add tests. All of them would fail with a
054: * BufferOverflowException.
055: *
056: * @return false
057: */
058: public boolean isAddSupported() {
059: return false;
060: }
061:
062: /**
063: * Overridden because the add operations raise BufferOverflowException
064: * instead of UnsupportedOperationException.
065: */
066: public void testUnsupportedAdd() {
067: }
068:
069: /**
070: * Tests to make sure the add operations raise BufferOverflowException.
071: */
072: public void testBufferOverflow() {
073: resetFull();
074: try {
075: collection.add(getOtherElements()[0]);
076: fail("add should raise BufferOverflow.");
077: } catch (BufferOverflowException e) {
078: // expected
079: }
080: verify();
081:
082: try {
083: collection.addAll(Arrays.asList(getOtherElements()));
084: fail("addAll should raise BufferOverflow.");
085: } catch (BufferOverflowException e) {
086: // expected
087: }
088: verify();
089: }
090:
091: /**
092: * Tests is full
093: */
094: public void testIsFull() {
095: resetFull();
096: assertEquals(true, ((BoundedCollection) collection).isFull());
097: ((BoundedFifoBuffer) collection).remove();
098: assertEquals(false, ((BoundedCollection) collection).isFull());
099: ((BoundedFifoBuffer) collection).add("jj");
100: assertEquals(true, ((BoundedCollection) collection).isFull());
101: }
102:
103: /**
104: * Tests max size
105: */
106: public void testMaxSize() {
107: resetFull();
108: assertEquals(getFullElements().length,
109: ((BoundedCollection) collection).maxSize());
110: ((BoundedFifoBuffer) collection).remove();
111: assertEquals(getFullElements().length,
112: ((BoundedCollection) collection).maxSize());
113: ((BoundedFifoBuffer) collection).add("jj");
114: assertEquals(getFullElements().length,
115: ((BoundedCollection) collection).maxSize());
116: }
117:
118: }
|