KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > 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;
17
18 import java.util.Arrays JavaDoc;
19 import java.util.Collection JavaDoc;
20
21 import junit.framework.Test;
22
23 /**
24  * Runs tests against a full BoundedFifoBuffer, since many of the algorithms
25  * differ depending on whether the fifo is full or not.
26  *
27  * @version $Revision: 1.10 $ $Date: 2004/02/18 01:20:35 $
28  *
29  * @author Unknown
30  */

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

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

59     public boolean isAddSupported() {
60         return false;
61     }
62
63
64     /**
65      * Overridden because the add operations raise BufferOverflowException
66      * instead of UnsupportedOperationException.
67      */

68     public void testUnsupportedAdd() {
69     }
70
71
72     /**
73      * Tests to make sure the add operations raise BufferOverflowException.
74      */

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

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

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