KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2003-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.Collection JavaDoc;
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23 import org.apache.commons.collections.ArrayStack;
24 import org.apache.commons.collections.Buffer;
25 import org.apache.commons.collections.BufferUnderflowException;
26 import org.apache.commons.collections.Predicate;
27 import org.apache.commons.collections.collection.TestPredicatedCollection;
28
29 /**
30  * Extension of {@link TestPredicatedCollection} for exercising the
31  * {@link PredicatedBuffer} implementation.
32  *
33  * @since Commons Collections 3.0
34  * @version $Revision: 1.4 $ $Date: 2004/06/02 22:05:54 $
35  *
36  * @author Phil Steitz
37  */

38 public class TestPredicatedBuffer extends TestPredicatedCollection {
39     
40     public TestPredicatedBuffer(String JavaDoc testName) {
41         super(testName);
42     }
43     
44     public static Test suite() {
45         return new TestSuite(TestPredicatedBuffer.class);
46     }
47     
48     public static void main(String JavaDoc args[]) {
49         String JavaDoc[] testCaseName = { TestPredicatedBuffer.class.getName()};
50         junit.textui.TestRunner.main(testCaseName);
51     }
52     
53     //---------------------------------------------------------------
54

55     protected Buffer decorateBuffer(Buffer buffer, Predicate predicate) {
56         return PredicatedBuffer.decorate(buffer, predicate);
57     }
58     
59     public Collection JavaDoc makeCollection() {
60         return decorateBuffer(new ArrayStack(), truePredicate);
61     }
62     
63     public Collection JavaDoc makeConfirmedCollection() {
64         return new ArrayStack();
65     }
66     
67     public Collection JavaDoc makeConfirmedFullCollection() {
68         ArrayStack list = new ArrayStack();
69         list.addAll(java.util.Arrays.asList(getFullElements()));
70         return list;
71     }
72     
73     //------------------------------------------------------------
74

75     public Buffer makeTestBuffer() {
76         return decorateBuffer(new ArrayStack(), testPredicate);
77     }
78     
79     public void testGet() {
80         Buffer buffer = makeTestBuffer();
81         try {
82             Object JavaDoc o = buffer.get();
83             fail("Expecting BufferUnderflowException");
84         } catch (BufferUnderflowException ex) {
85             // expected
86
}
87         buffer.add("one");
88         buffer.add("two");
89         buffer.add("three");
90         assertEquals("Buffer get", buffer.get(), "three");
91     }
92     
93     public void testRemove() {
94         Buffer buffer = makeTestBuffer();
95         buffer.add("one");
96         assertEquals("Buffer get", buffer.remove(), "one");
97         try {
98             buffer.remove();
99             fail("Expecting BufferUnderflowException");
100         } catch (BufferUnderflowException ex) {
101             // expected
102
}
103     }
104
105     public String JavaDoc getCompatibilityVersion() {
106         return "3.1";
107     }
108
109 // public void testCreate() throws Exception {
110
// resetEmpty();
111
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.emptyCollection.version3.1.obj");
112
// resetFull();
113
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.fullCollection.version3.1.obj");
114
// }
115

116 }
117
Popular Tags