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.set;
17:
18: import java.util.Arrays;
19: import java.util.HashSet;
20: import java.util.Set;
21: import java.util.SortedSet;
22: import java.util.TreeSet;
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: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
35: *
36: * @author Stephen Colebourne
37: */
38: public class TestTransformedSortedSet extends AbstractTestSortedSet {
39:
40: public TestTransformedSortedSet(String 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 args[]) {
49: String[] testCaseName = { TestTransformedSortedSet.class
50: .getName() };
51: junit.textui.TestRunner.main(testCaseName);
52: }
53:
54: //-----------------------------------------------------------------------
55: public Set makeEmptySet() {
56: return TransformedSortedSet.decorate(new TreeSet(),
57: TestTransformedCollection.NOOP_TRANSFORMER);
58: }
59:
60: public Set makeFullSet() {
61: SortedSet set = new TreeSet();
62: set.addAll(Arrays.asList(getFullElements()));
63: return TransformedSortedSet.decorate(set,
64: TestTransformedCollection.NOOP_TRANSFORMER);
65: }
66:
67: //-----------------------------------------------------------------------
68: public void testTransformedSet() {
69: Set set = TransformedSortedSet
70: .decorate(
71: new HashSet(),
72: TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
73: assertEquals(0, set.size());
74: Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
75: for (int i = 0; i < els.length; i++) {
76: set.add(els[i]);
77: assertEquals(i + 1, set.size());
78: assertEquals(true, set
79: .contains(new Integer((String) 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((String) els[0])));
85:
86: }
87:
88: public String 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/TransformedSortedSet.emptyCollection.version3.1.obj");
95: // resetFull();
96: // writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/TransformedSortedSet.fullCollection.version3.1.obj");
97: // }
98:
99: }
|