001: /*
002: * Copyright 2003-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.set;
017:
018: import java.util.Arrays;
019: import java.util.Collection;
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import junit.framework.Test;
024: import junit.framework.TestSuite;
025:
026: import org.apache.commons.collections.collection.TestTransformedCollection;
027:
028: /**
029: * Extension of {@link TestSet} for exercising the {@link TransformedSet}
030: * implementation.
031: *
032: * @since Commons Collections 3.0
033: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
034: *
035: * @author Stephen Colebourne
036: */
037: public class TestTransformedSet extends AbstractTestSet {
038:
039: public TestTransformedSet(String testName) {
040: super (testName);
041: }
042:
043: public static Test suite() {
044: return new TestSuite(TestTransformedSet.class);
045: }
046:
047: public static void main(String args[]) {
048: String[] testCaseName = { TestTransformedSet.class.getName() };
049: junit.textui.TestRunner.main(testCaseName);
050: }
051:
052: public Collection makeConfirmedCollection() {
053: return new HashSet();
054: }
055:
056: public Collection makeConfirmedFullCollection() {
057: Set set = new HashSet();
058: set.addAll(Arrays.asList(getFullElements()));
059: return set;
060: }
061:
062: public Set makeEmptySet() {
063: return TransformedSet.decorate(new HashSet(),
064: TestTransformedCollection.NOOP_TRANSFORMER);
065: }
066:
067: public Set makeFullSet() {
068: Set list = new HashSet();
069: list.addAll(Arrays.asList(getFullElements()));
070: return TransformedSet.decorate(list,
071: TestTransformedCollection.NOOP_TRANSFORMER);
072: }
073:
074: public void testTransformedSet() {
075: Set set = TransformedSet
076: .decorate(
077: new HashSet(),
078: TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
079: assertEquals(0, set.size());
080: Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
081: for (int i = 0; i < els.length; i++) {
082: set.add(els[i]);
083: assertEquals(i + 1, set.size());
084: assertEquals(true, set
085: .contains(new Integer((String) els[i])));
086: assertEquals(false, set.contains(els[i]));
087: }
088:
089: assertEquals(false, set.remove(els[0]));
090: assertEquals(true, set.remove(new Integer((String) els[0])));
091:
092: }
093:
094: public String getCompatibilityVersion() {
095: return "3.1";
096: }
097:
098: // public void testCreate() throws Exception {
099: // resetEmpty();
100: // writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/TransformedSet.emptyCollection.version3.1.obj");
101: // resetFull();
102: // writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/TransformedSet.fullCollection.version3.1.obj");
103: // }
104:
105: }
|