1 16 package org.apache.commons.collections.set; 17 18 import java.util.Arrays ; 19 import java.util.Collection ; 20 import java.util.HashSet ; 21 import java.util.Set ; 22 23 import junit.framework.Test; 24 import junit.framework.TestSuite; 25 26 import org.apache.commons.collections.collection.TestTransformedCollection; 27 28 37 public class TestTransformedSet extends AbstractTestSet { 38 39 public TestTransformedSet(String 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 args[]) { 48 String [] testCaseName = { TestTransformedSet.class.getName()}; 49 junit.textui.TestRunner.main(testCaseName); 50 } 51 52 public Collection makeConfirmedCollection() { 53 return new HashSet (); 54 } 55 56 public Collection makeConfirmedFullCollection() { 57 Set set = new HashSet (); 58 set.addAll(Arrays.asList(getFullElements())); 59 return set; 60 } 61 62 public Set makeEmptySet() { 63 return TransformedSet.decorate(new HashSet (), TestTransformedCollection.NOOP_TRANSFORMER); 64 } 65 66 public Set makeFullSet() { 67 Set list = new HashSet (); 68 list.addAll(Arrays.asList(getFullElements())); 69 return TransformedSet.decorate(list, TestTransformedCollection.NOOP_TRANSFORMER); 70 } 71 72 public void testTransformedSet() { 73 Set set = TransformedSet.decorate(new HashSet (), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); 74 assertEquals(0, set.size()); 75 Object [] els = new Object [] {"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 ((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 99 } 100 | Popular Tags |