KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

92 }
93
Popular Tags