KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestBag} for exercising the {@link TransformedBag}
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 TestTransformedBag extends AbstractTestBag {
34     
35     public TestTransformedBag(String JavaDoc 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 JavaDoc args[]) {
44         String JavaDoc[] testCaseName = { TestTransformedBag.class.getName()};
45         junit.textui.TestRunner.main(testCaseName);
46     }
47
48     public Bag makeBag() {
49         return TransformedBag.decorate(new HashBag(), TestTransformedCollection.NOOP_TRANSFORMER);
50     }
51
52     public void testTransformedBag() {
53         Bag bag = TransformedBag.decorate(new HashBag(), 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             assertEquals(false, bag.contains(els[i]));
61         }
62         
63         assertEquals(false, bag.remove(els[0]));
64         assertEquals(true, bag.remove(new Integer JavaDoc((String JavaDoc) els[0])));
65         
66     }
67
68     public String JavaDoc getCompatibilityVersion() {
69         return "3.1";
70     }
71
72 // public void testCreate() throws Exception {
73
// Bag bag = makeBag();
74
// writeExternalFormToDisk((java.io.Serializable) bag, "D:/dev/collections/data/test/TransformedBag.emptyCollection.version3.1.obj");
75
// bag = makeBag();
76
// bag.add("A");
77
// bag.add("A");
78
// bag.add("B");
79
// bag.add("B");
80
// bag.add("C");
81
// writeExternalFormToDisk((java.io.Serializable) bag, "D:/dev/collections/data/test/TransformedBag.fullCollection.version3.1.obj");
82
// }
83

84 }
85
Popular Tags