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 TestSortedBag} for exercising the {@link TransformedSortedBag}
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 TestTransformedSortedBag extends AbstractTestSortedBag {
34:
35: public TestTransformedSortedBag(String testName) {
36: super (testName);
37: }
38:
39: public static Test suite() {
40: return new TestSuite(TestTransformedSortedBag.class);
41: }
42:
43: public static void main(String args[]) {
44: String[] testCaseName = { TestTransformedSortedBag.class
45: .getName() };
46: junit.textui.TestRunner.main(testCaseName);
47: }
48:
49: public Bag makeBag() {
50: return TransformedSortedBag.decorate(new TreeBag(),
51: TestTransformedCollection.NOOP_TRANSFORMER);
52: }
53:
54: public void testTransformedBag() {
55: Bag bag = TransformedSortedBag
56: .decorate(
57: new TreeBag(),
58: TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
59: assertEquals(0, bag.size());
60: Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
61: for (int i = 0; i < els.length; i++) {
62: bag.add(els[i]);
63: assertEquals(i + 1, bag.size());
64: assertEquals(true, bag
65: .contains(new Integer((String) els[i])));
66: }
67:
68: assertEquals(true, bag.remove(new Integer((String) els[0])));
69:
70: }
71:
72: public String getCompatibilityVersion() {
73: return "3.1";
74: }
75:
76: // public void testCreate() throws Exception {
77: // Bag bag = makeBag();
78: // writeExternalFormToDisk((java.io.Serializable) bag, "D:/dev/collections/data/test/TransformedSortedBag.emptyCollection.version3.1.obj");
79: // bag = makeBag();
80: // bag.add("A");
81: // bag.add("A");
82: // bag.add("B");
83: // bag.add("B");
84: // bag.add("C");
85: // writeExternalFormToDisk((java.io.Serializable) bag, "D:/dev/collections/data/test/TransformedSortedBag.fullCollection.version3.1.obj");
86: // }
87:
88: }
|