KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import junit.framework.Test;
23
24 import org.apache.commons.collections.BulkTest;
25 import org.apache.commons.collections.collection.AbstractTestCollection;
26
27 /**
28  * Test cases for UnboundedFifoBuffer.
29  *
30  * @version $Revision: 1.4 $ $Date: 2004/06/01 22:55:54 $
31  *
32  * @author Unknown
33  */

34 public class TestUnboundedFifoBuffer extends AbstractTestCollection {
35
36     public TestUnboundedFifoBuffer(String JavaDoc n) {
37         super(n);
38     }
39
40     public static Test suite() {
41         return BulkTest.makeSuite(TestUnboundedFifoBuffer.class);
42     }
43
44     //-----------------------------------------------------------------------
45
/**
46      * Verifies that the ArrayList has the same elements in the same
47      * sequence as the UnboundedFifoBuffer.
48      */

49     public void verify() {
50         super.verify();
51         Iterator JavaDoc iterator1 = collection.iterator();
52         Iterator JavaDoc iterator2 = confirmed.iterator();
53         while (iterator2.hasNext()) {
54             assertTrue(iterator1.hasNext());
55             Object JavaDoc o1 = iterator1.next();
56             Object JavaDoc o2 = iterator2.next();
57             assertEquals(o1, o2);
58         }
59     }
60
61     //-----------------------------------------------------------------------
62
/**
63      * Overridden because UnboundedFifoBuffer doesn't allow null elements.
64      * @return false
65      */

66     public boolean isNullSupported() {
67         return false;
68     }
69
70     /**
71      * Overridden because UnboundedFifoBuffer isn't fail fast.
72      * @return false
73      */

74     public boolean isFailFastSupported() {
75         return false;
76     }
77
78     //-----------------------------------------------------------------------
79
/**
80      * Returns an empty ArrayList.
81      *
82      * @return an empty ArrayList
83      */

84     public Collection JavaDoc makeConfirmedCollection() {
85         return new ArrayList JavaDoc();
86     }
87
88     /**
89      * Returns a full ArrayList.
90      *
91      * @return a full ArrayList
92      */

93     public Collection JavaDoc makeConfirmedFullCollection() {
94         Collection JavaDoc c = makeConfirmedCollection();
95         c.addAll(java.util.Arrays.asList(getFullElements()));
96         return c;
97     }
98
99     /**
100      * Returns an empty UnboundedFifoBuffer with a small capacity.
101      *
102      * @return an empty UnboundedFifoBuffer
103      */

104     public Collection JavaDoc makeCollection() {
105         return new UnboundedFifoBuffer(5);
106     }
107
108     //-----------------------------------------------------------------------
109
/**
110      * Tests that UnboundedFifoBuffer removes elements in the right order.
111      */

112     public void testUnboundedFifoBufferRemove() {
113         resetFull();
114         int size = confirmed.size();
115         for (int i = 0; i < size; i++) {
116             Object JavaDoc o1 = ((UnboundedFifoBuffer)collection).remove();
117             Object JavaDoc o2 = ((ArrayList JavaDoc)confirmed).remove(0);
118             assertEquals("Removed objects should be equal", o1, o2);
119             verify();
120         }
121     }
122
123     /**
124      * Tests that the constructor correctly throws an exception.
125      */

126     public void testConstructorException1() {
127         try {
128             new UnboundedFifoBuffer(0);
129         } catch (IllegalArgumentException JavaDoc ex) {
130             return;
131         }
132         fail();
133     }
134     
135     /**
136      * Tests that the constructor correctly throws an exception.
137      */

138     public void testConstructorException2() {
139         try {
140             new UnboundedFifoBuffer(-20);
141         } catch (IllegalArgumentException JavaDoc ex) {
142             return;
143         }
144         fail();
145     }
146
147     public String JavaDoc getCompatibilityVersion() {
148         return "3.1";
149     }
150
151 // public void testCreate() throws Exception {
152
// resetEmpty();
153
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/UnboundedFifoBuffer.emptyCollection.version3.1.obj");
154
// resetFull();
155
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/UnboundedFifoBuffer.fullCollection.version3.1.obj");
156
// }
157

158 }
159
Popular Tags