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.SortedBag; 23 24 32 public class TestTreeBag extends AbstractTestBag { 33 34 public TestTreeBag(String testName) { 35 super(testName); 36 } 37 38 public static Test suite() { 39 return new TestSuite(TestTreeBag.class); 40 } 41 42 public static void main(String args[]) { 43 String [] testCaseName = { TestTreeBag.class.getName() }; 44 junit.textui.TestRunner.main(testCaseName); 45 } 46 47 public Bag makeBag() { 48 return new TreeBag(); 49 } 50 51 public SortedBag setupBag() { 52 SortedBag bag = (SortedBag)makeBag(); 53 bag.add("C"); 54 bag.add("A"); 55 bag.add("B"); 56 bag.add("D"); 57 return bag; 58 } 59 60 public void testOrdering() { 61 Bag bag = setupBag(); 62 assertEquals("Should get elements in correct order", 63 "A", bag.toArray()[0]); 64 assertEquals("Should get elements in correct order", 65 "B", bag.toArray()[1]); 66 assertEquals("Should get elements in correct order", 67 "C", bag.toArray()[2]); 68 assertEquals("Should get first key", 69 "A", ((SortedBag)bag).first()); 70 assertEquals("Should get last key", 71 "D", ((SortedBag)bag).last()); 72 } 73 74 public String getCompatibilityVersion() { 75 return "3"; 76 } 77 78 } 90 | Popular Tags |