KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > bag > TestTransformedSortedBag


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.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: 1.7 $ $Date: 2004/06/02 22:05:03 $
30  *
31  * @author Stephen Colebourne
32  */

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

82 }
83
Popular Tags