01: /*
02: * Copyright 2003-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
32: *
33: * @author Stephen Colebourne
34: */
35: public class TestTransformedBuffer extends TestCase {
36:
37: public TestTransformedBuffer(String 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 args[]) {
46: String[] testCaseName = { TestTransformedBuffer.class.getName() };
47: junit.textui.TestRunner.main(testCaseName);
48: }
49:
50: public void testTransformedBuffer() {
51: Buffer buffer = TransformedBuffer
52: .decorate(
53: new ArrayStack(),
54: TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
55: assertEquals(0, buffer.size());
56: Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
57: for (int i = 0; i < els.length; i++) {
58: buffer.add(els[i]);
59: assertEquals(i + 1, buffer.size());
60: assertEquals(true, buffer.contains(new Integer(
61: (String) els[i])));
62: assertEquals(false, buffer.contains(els[i]));
63: }
64:
65: assertEquals(false, buffer.remove(els[0]));
66: assertEquals(true, buffer.remove(new Integer((String) els[0])));
67:
68: }
69: }
|