1 16 package org.apache.commons.collections; 17 18 import junit.framework.Test; 19 import junit.framework.TestSuite; 20 21 import org.apache.commons.collections.bag.AbstractTestBag; 22 23 31 public class TestTreeBag extends AbstractTestBag { 32 33 public TestTreeBag(String testName) { 34 super(testName); 35 } 36 37 public static Test suite() { 38 return new TestSuite(TestTreeBag.class); 39 } 40 41 public static void main(String args[]) { 42 String [] testCaseName = { TestTreeBag.class.getName() }; 43 junit.textui.TestRunner.main(testCaseName); 44 } 45 46 public Bag makeBag() { 47 return new TreeBag(); 48 } 49 50 public SortedBag setupBag() { 51 SortedBag bag = (SortedBag)makeBag(); 52 bag.add("C"); 53 bag.add("A"); 54 bag.add("B"); 55 bag.add("D"); 56 return bag; 57 } 58 59 public void testOrdering() { 60 Bag bag = setupBag(); 61 assertEquals("Should get elements in correct order", 62 "A", bag.toArray()[0]); 63 assertEquals("Should get elements in correct order", 64 "B", bag.toArray()[1]); 65 assertEquals("Should get elements in correct order", 66 "C", bag.toArray()[2]); 67 assertEquals("Should get first key", 68 "A", ((SortedBag)bag).first()); 69 assertEquals("Should get last key", 70 "D", ((SortedBag)bag).last()); 71 } 72 } 73 | Popular Tags |