1 16 package org.apache.commons.collections.bag; 17 18 import junit.framework.Test; 19 import junit.framework.TestSuite; 20 21 import org.apache.commons.collections.Bag; 22 import org.apache.commons.collections.collection.TestTransformedCollection; 23 24 33 public class TestTransformedBag extends AbstractTestBag { 34 35 public TestTransformedBag(String testName) { 36 super(testName); 37 } 38 39 public static Test suite() { 40 return new TestSuite(TestTransformedBag.class); 41 } 42 43 public static void main(String args[]) { 44 String [] testCaseName = { TestTransformedBag.class.getName()}; 45 junit.textui.TestRunner.main(testCaseName); 46 } 47 48 public Bag makeBag() { 49 return TransformedBag.decorate(new HashBag(), TestTransformedCollection.NOOP_TRANSFORMER); 50 } 51 52 public void testTransformedBag() { 53 Bag bag = TransformedBag.decorate(new HashBag(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); 54 assertEquals(0, bag.size()); 55 Object [] els = new Object [] {"1", "3", "5", "7", "2", "4", "6"}; 56 for (int i = 0; i < els.length; i++) { 57 bag.add(els[i]); 58 assertEquals(i + 1, bag.size()); 59 assertEquals(true, bag.contains(new Integer ((String ) els[i]))); 60 assertEquals(false, bag.contains(els[i])); 61 } 62 63 assertEquals(false, bag.remove(els[0])); 64 assertEquals(true, bag.remove(new Integer ((String ) els[0]))); 65 66 } 67 68 public String getCompatibilityVersion() { 69 return "3.1"; 70 } 71 72 84 } 85 | Popular Tags |