KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Test;
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21
22 import org.apache.commons.collections.ArrayStack;
23 import org.apache.commons.collections.Buffer;
24 import org.apache.commons.collections.collection.TestTransformedCollection;
25
26 /**
27  * Extension of {@link TestBuffer} for exercising the {@link TransformedBuffer}
28  * implementation.
29  *
30  * @since Commons Collections 3.0
31  * @version $Revision: 1.3 $ $Date: 2004/02/18 01:20:37 $
32  *
33  * @author Stephen Colebourne
34  */

35 public class TestTransformedBuffer extends TestCase {
36     
37     public TestTransformedBuffer(String JavaDoc testName) {
38         super(testName);
39     }
40
41     public static Test suite() {
42         return new TestSuite(TestTransformedBuffer.class);
43     }
44
45     public static void main(String JavaDoc args[]) {
46         String JavaDoc[] testCaseName = { TestTransformedBuffer.class.getName()};
47         junit.textui.TestRunner.main(testCaseName);
48     }
49
50     public void testTransformedBuffer() {
51         Buffer buffer = TransformedBuffer.decorate(new ArrayStack(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
52         assertEquals(0, buffer.size());
53         Object JavaDoc[] els = new Object JavaDoc[] {"1", "3", "5", "7", "2", "4", "6"};
54         for (int i = 0; i < els.length; i++) {
55             buffer.add(els[i]);
56             assertEquals(i + 1, buffer.size());
57             assertEquals(true, buffer.contains(new Integer JavaDoc((String JavaDoc) els[i])));
58             assertEquals(false, buffer.contains(els[i]));
59         }
60         
61         assertEquals(false, buffer.remove(els[0]));
62         assertEquals(true, buffer.remove(new Integer JavaDoc((String JavaDoc) els[0])));
63         
64     }
65 }
66
Popular Tags