KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > 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;
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.collection.AbstractTestCollection;
25
26 /**
27  * Test cases for UnboundedFifoBuffer.
28  *
29  * @version $Revision: 1.12 $ $Date: 2004/02/18 01:20:35 $
30  *
31  * @author Unknown
32  */

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

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

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

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

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

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

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

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

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

137     public void testConstructorException2() {
138         try {
139             new UnboundedFifoBuffer(-20);
140         } catch (IllegalArgumentException JavaDoc ex) {
141             return;
142         }
143         fail();
144     }
145 }
146
147
Popular Tags