KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > buffer > TestBoundedFifoBuffer2


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.buffer;
17
18 import java.util.Arrays JavaDoc;
19 import java.util.Collection JavaDoc;
20
21 import junit.framework.Test;
22
23 import org.apache.commons.collections.BoundedCollection;
24 import org.apache.commons.collections.BufferOverflowException;
25 import org.apache.commons.collections.BulkTest;
26
27 /**
28  * Runs tests against a full BoundedFifoBuffer, since many of the algorithms
29  * differ depending on whether the fifo is full or not.
30  *
31  * @version $Revision: 1.4 $ $Date: 2004/02/18 01:20:37 $
32  *
33  * @author Unknown
34  */

35 public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer {
36
37     public TestBoundedFifoBuffer2(String JavaDoc n) {
38         super(n);
39     }
40
41     public static Test suite() {
42         return BulkTest.makeSuite(TestBoundedFifoBuffer2.class);
43     }
44
45     /**
46      * Returns a BoundedFifoBuffer that's filled to capacity.
47      * Any attempt to add to the returned buffer will result in a
48      * BufferOverflowException.
49      *
50      * @return a full BoundedFifoBuffer
51      */

52     public Collection JavaDoc makeFullCollection() {
53         return new BoundedFifoBuffer(Arrays.asList(getFullElements()));
54     }
55
56
57     /**
58      * Overridden to skip the add tests. All of them would fail with a
59      * BufferOverflowException.
60      *
61      * @return false
62      */

63     public boolean isAddSupported() {
64         return false;
65     }
66
67
68     /**
69      * Overridden because the add operations raise BufferOverflowException
70      * instead of UnsupportedOperationException.
71      */

72     public void testUnsupportedAdd() {
73     }
74
75
76     /**
77      * Tests to make sure the add operations raise BufferOverflowException.
78      */

79     public void testBufferOverflow() {
80         resetFull();
81         try {
82             collection.add(getOtherElements()[0]);
83             fail("add should raise BufferOverflow.");
84         } catch (BufferOverflowException e) {
85             // expected
86
}
87         verify();
88
89         try {
90             collection.addAll(Arrays.asList(getOtherElements()));
91             fail("addAll should raise BufferOverflow.");
92         } catch (BufferOverflowException e) {
93             // expected
94
}
95         verify();
96     }
97
98     /**
99      * Tests is full
100      */

101     public void testIsFull() {
102         resetFull();
103         assertEquals(true, ((BoundedCollection) collection).isFull());
104         ((BoundedFifoBuffer) collection).remove();
105         assertEquals(false, ((BoundedCollection) collection).isFull());
106         ((BoundedFifoBuffer) collection).add("jj");
107         assertEquals(true, ((BoundedCollection) collection).isFull());
108     }
109
110     /**
111      * Tests max size
112      */

113     public void testMaxSize() {
114         resetFull();
115         assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize());
116         ((BoundedFifoBuffer) collection).remove();
117         assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize());
118         ((BoundedFifoBuffer) collection).add("jj");
119         assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize());
120     }
121
122 }
123
124
Popular Tags