KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > set > TestTransformedSet


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.set;
17
18 import java.util.Arrays JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 import org.apache.commons.collections.collection.TestTransformedCollection;
27
28 /**
29  * Extension of {@link TestSet} for exercising the {@link TransformedSet}
30  * implementation.
31  *
32  * @since Commons Collections 3.0
33  * @version $Revision: 1.6 $ $Date: 2004/06/02 22:12:14 $
34  *
35  * @author Stephen Colebourne
36  */

37 public class TestTransformedSet extends AbstractTestSet {
38     
39     public TestTransformedSet(String JavaDoc testName) {
40         super(testName);
41     }
42
43     public static Test suite() {
44         return new TestSuite(TestTransformedSet.class);
45     }
46
47     public static void main(String JavaDoc args[]) {
48         String JavaDoc[] testCaseName = { TestTransformedSet.class.getName()};
49         junit.textui.TestRunner.main(testCaseName);
50     }
51
52     public Collection JavaDoc makeConfirmedCollection() {
53         return new HashSet JavaDoc();
54     }
55
56     public Collection JavaDoc makeConfirmedFullCollection() {
57         Set JavaDoc set = new HashSet JavaDoc();
58         set.addAll(Arrays.asList(getFullElements()));
59         return set;
60     }
61     
62     public Set JavaDoc makeEmptySet() {
63         return TransformedSet.decorate(new HashSet JavaDoc(), TestTransformedCollection.NOOP_TRANSFORMER);
64     }
65
66     public Set JavaDoc makeFullSet() {
67         Set JavaDoc list = new HashSet JavaDoc();
68         list.addAll(Arrays.asList(getFullElements()));
69         return TransformedSet.decorate(list, TestTransformedCollection.NOOP_TRANSFORMER);
70     }
71     
72     public void testTransformedSet() {
73         Set JavaDoc set = TransformedSet.decorate(new HashSet JavaDoc(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
74         assertEquals(0, set.size());
75         Object JavaDoc[] els = new Object JavaDoc[] {"1", "3", "5", "7", "2", "4", "6"};
76         for (int i = 0; i < els.length; i++) {
77             set.add(els[i]);
78             assertEquals(i + 1, set.size());
79             assertEquals(true, set.contains(new Integer JavaDoc((String JavaDoc) els[i])));
80             assertEquals(false, set.contains(els[i]));
81         }
82         
83         assertEquals(false, set.remove(els[0]));
84         assertEquals(true, set.remove(new Integer JavaDoc((String JavaDoc) els[0])));
85         
86     }
87
88     public String JavaDoc getCompatibilityVersion() {
89         return "3.1";
90     }
91
92 // public void testCreate() throws Exception {
93
// resetEmpty();
94
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/TransformedSet.emptyCollection.version3.1.obj");
95
// resetFull();
96
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/TransformedSet.fullCollection.version3.1.obj");
97
// }
98

99 }
100
Popular Tags