1 16 package org.apache.commons.collections.bag; 17 18 import java.util.Comparator ; 19 20 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 import org.apache.commons.collections.Bag; 24 import org.apache.commons.collections.SortedBag; 25 26 35 public class TestTypedSortedBag extends AbstractTestSortedBag { 36 37 public TestTypedSortedBag(String testName) { 38 super(testName); 39 } 40 41 public static Test suite() { 42 return new TestSuite(TestTypedSortedBag.class); 43 } 44 45 public static void main(String args[]) { 46 String [] testCaseName = { TestTypedSortedBag.class.getName()}; 47 junit.textui.TestRunner.main(testCaseName); 48 } 49 50 52 protected Class stringClass = this.getName().getClass(); 53 private Object obj = new Object (); 54 protected Class objectClass = obj.getClass(); 55 protected SortedBag nullBag = null; 56 57 protected SortedBag decorateBag(SortedBag bag, Class claz) { 58 return TypedSortedBag.decorate(bag, claz); 59 } 60 61 public Bag makeBag() { 62 return decorateBag(new TreeBag(), objectClass); 63 } 64 65 protected Bag makeTestBag() { 66 return decorateBag(new TreeBag(), stringClass); 67 } 68 69 71 public void testDecorate() { 72 SortedBag bag = decorateBag(new TreeBag(), stringClass); 73 try { 74 SortedBag bag3 = decorateBag(new TreeBag(), null); 75 fail("Expecting IllegalArgumentException for null predicate"); 76 } catch (IllegalArgumentException e) {} 77 try { 78 SortedBag bag4 = decorateBag(nullBag, stringClass); 79 fail("Expecting IllegalArgumentException for null bag"); 80 } catch (IllegalArgumentException e) {} 81 } 82 83 public void testSortOrder() { 84 SortedBag bag = decorateBag(new TreeBag(), stringClass); 85 String one = "one"; 86 String two = "two"; 87 String three = "three"; 88 bag.add(one); 89 bag.add(two); 90 bag.add(three); 91 assertEquals("first element", bag.first(), one); 92 assertEquals("last element", bag.last(), two); 93 Comparator c = bag.comparator(); 94 assertTrue("natural order, so comparator should be null", c == null); 95 } 96 97 protected boolean skipSerializedCanonicalTests() { 98 return true; 99 } 100 101 } 102 | Popular Tags |