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.bag;
17:
18: import junit.framework.Test;
19: import junit.framework.TestSuite;
20:
21: import org.apache.commons.collections.Bag;
22: import org.apache.commons.collections.collection.TestTransformedCollection;
23:
24: /**
25: * Extension of {@link TestBag} for exercising the {@link TransformedBag}
26: * implementation.
27: *
28: * @since Commons Collections 3.0
29: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
30: *
31: * @author Stephen Colebourne
32: */
33: public class TestTransformedBag extends AbstractTestBag {
34:
35: public TestTransformedBag(String testName) {
36: super (testName);
37: }
38:
39: public static Test suite() {
40: return new TestSuite(TestTransformedBag.class);
41: }
42:
43: public static void main(String args[]) {
44: String[] testCaseName = { TestTransformedBag.class.getName() };
45: junit.textui.TestRunner.main(testCaseName);
46: }
47:
48: public Bag makeBag() {
49: return TransformedBag.decorate(new HashBag(),
50: TestTransformedCollection.NOOP_TRANSFORMER);
51: }
52:
53: public void testTransformedBag() {
54: Bag bag = TransformedBag
55: .decorate(
56: new HashBag(),
57: TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
58: assertEquals(0, bag.size());
59: Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
60: for (int i = 0; i < els.length; i++) {
61: bag.add(els[i]);
62: assertEquals(i + 1, bag.size());
63: assertEquals(true, bag
64: .contains(new Integer((String) els[i])));
65: assertEquals(false, bag.contains(els[i]));
66: }
67:
68: assertEquals(false, bag.remove(els[0]));
69: assertEquals(true, bag.remove(new Integer((String) els[0])));
70:
71: }
72:
73: public String getCompatibilityVersion() {
74: return "3.1";
75: }
76:
77: // public void testCreate() throws Exception {
78: // Bag bag = makeBag();
79: // writeExternalFormToDisk((java.io.Serializable) bag, "D:/dev/collections/data/test/TransformedBag.emptyCollection.version3.1.obj");
80: // bag = makeBag();
81: // bag.add("A");
82: // bag.add("A");
83: // bag.add("B");
84: // bag.add("B");
85: // bag.add("C");
86: // writeExternalFormToDisk((java.io.Serializable) bag, "D:/dev/collections/data/test/TransformedBag.fullCollection.version3.1.obj");
87: // }
88:
89: }
|