1 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 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.getName()}; 50 junit.textui.TestRunner.main(testCaseName); 51 } 52 53 public Set makeEmptySet() { 55 return TransformedSortedSet.decorate(new TreeSet (), TestTransformedCollection.NOOP_TRANSFORMER); 56 } 57 58 public Set makeFullSet() { 59 SortedSet set = new TreeSet (); 60 set.addAll(Arrays.asList(getFullElements())); 61 return TransformedSortedSet.decorate(set, TestTransformedCollection.NOOP_TRANSFORMER); 62 } 63 64 public void testTransformedSet() { 66 Set set = TransformedSortedSet.decorate(new HashSet (), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); 67 assertEquals(0, set.size()); 68 Object [] els = new Object [] {"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 ((String ) 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 ((String ) els[0]))); 78 79 } 80 81 public String getCompatibilityVersion() { 82 return "3.1"; 83 } 84 85 92 } 93 | Popular Tags |