1 7 package test.beans; 8 9 import java.util.ArrayList ; 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 13 import org.ejtools.beans.Sort; 14 15 import junit.framework.TestCase; 16 17 21 public class SortTest extends TestCase 22 { 23 private Collection content; 24 25 26 27 public SortTest() 28 { 29 super(); 30 } 31 32 33 38 public SortTest(String name) 39 { 40 super(name); 41 } 42 43 44 45 public void testGetChildrenByClass() 46 { 47 int i = 0; 48 for (Iterator it = Sort.getChildrenByClass(this.content.iterator(), String .class); it.hasNext(); i++) 49 { 50 it.next(); 51 } 52 assertEquals("Four elements must be found", i, 4); 53 54 i = 0; 55 for (Iterator it = Sort.getChildrenByClass(this.content.iterator(), Double .class); it.hasNext(); i++) 56 { 57 it.next(); 58 } 59 assertEquals("Tow elements must be found", i, 2); 60 61 i = 0; 62 for (Iterator it = Sort.getChildrenByClass(this.content.iterator(), Object .class); it.hasNext(); i++) 63 { 64 it.next(); 65 } 66 assertEquals("Eight elements must be found", i, 8); 67 } 68 69 70 71 public void testSortByClass() 72 { 73 int i = 0; 74 for (Iterator it = Sort.sortByClass(this.content.iterator()); it.hasNext(); i++) 75 { 76 Object o = it.next(); 77 switch (i) 78 { 79 case 0: 80 assertEquals("Class is not correct", Double .class, o.getClass()); 81 break; 82 case 1: 83 assertEquals("Class is not correct", Double .class, o.getClass()); 84 break; 85 case 2: 86 assertEquals("Class is not correct", Object .class, o.getClass()); 87 break; 88 case 3: 89 assertEquals("Class is not correct", Object .class, o.getClass()); 90 break; 91 case 4: 92 assertEquals("Class is not correct", String .class, o.getClass()); 93 break; 94 case 5: 95 assertEquals("Class is not correct", String .class, o.getClass()); 96 break; 97 case 6: 98 assertEquals("Class is not correct", String .class, o.getClass()); 99 break; 100 case 7: 101 assertEquals("Class is not correct", String .class, o.getClass()); 102 break; 103 default: 104 } 105 } 106 } 107 108 109 110 public void testSortByClassAndName() 111 { 112 int i = 0; 113 for (Iterator it = Sort.sortByClassAndName(this.content.iterator()); it.hasNext(); i++) 114 { 115 Object o = it.next(); 116 switch (i) 117 { 118 case 0: 119 assertEquals("Class is not correct", Double .class, o.getClass()); 120 assertEquals("Name is not correct", "0.0", o.toString()); 121 break; 122 case 1: 123 assertEquals("Class is not correct", Double .class, o.getClass()); 124 assertEquals("Name is not correct", "1.0", o.toString()); 125 break; 126 case 2: 127 assertEquals("Class is not correct", Object .class, o.getClass()); 128 break; 129 case 3: 130 assertEquals("Class is not correct", Object .class, o.getClass()); 131 break; 132 case 4: 133 assertEquals("Class is not correct", String .class, o.getClass()); 134 assertEquals("Name is not correct", "s0", o.toString()); 135 break; 136 case 5: 137 assertEquals("Class is not correct", String .class, o.getClass()); 138 assertEquals("Name is not correct", "s1", o.toString()); 139 break; 140 case 6: 141 assertEquals("Class is not correct", String .class, o.getClass()); 142 assertEquals("Name is not correct", "s2", o.toString()); 143 break; 144 case 7: 145 assertEquals("Class is not correct", String .class, o.getClass()); 146 assertEquals("Name is not correct", "s3", o.toString()); 147 break; 148 default: 149 } 150 } 151 } 152 153 154 155 public void testSortByName() 156 { 157 int i = 0; 158 for (Iterator it = Sort.sortByName(this.content.iterator()); it.hasNext(); i++) 159 { 160 Object o = it.next(); 161 switch (i) 162 { 163 case 0: 164 assertEquals("Class is not correct", Double .class, o.getClass()); 165 assertEquals("Name is not correct", "0.0", o.toString()); 166 break; 167 case 1: 168 assertEquals("Class is not correct", Double .class, o.getClass()); 169 assertEquals("Name is not correct", "1.0", o.toString()); 170 break; 171 case 2: 172 assertEquals("Class is not correct", Object .class, o.getClass()); 173 break; 174 case 3: 175 assertEquals("Class is not correct", Object .class, o.getClass()); 176 break; 177 case 4: 178 assertEquals("Class is not correct", String .class, o.getClass()); 179 assertEquals("Name is not correct", "s0", o.toString()); 180 break; 181 case 5: 182 assertEquals("Class is not correct", String .class, o.getClass()); 183 assertEquals("Name is not correct", "s1", o.toString()); 184 break; 185 case 6: 186 assertEquals("Class is not correct", String .class, o.getClass()); 187 assertEquals("Name is not correct", "s2", o.toString()); 188 break; 189 case 7: 190 assertEquals("Class is not correct", String .class, o.getClass()); 191 assertEquals("Name is not correct", "s3", o.toString()); 192 break; 193 default: 194 } 195 } 196 } 197 198 199 200 public void testSortByProperty() 201 { 202 } 203 204 205 210 protected void setUp() 211 throws Exception 212 { 213 this.content = new ArrayList (); 214 215 this.content.add("s0"); 216 this.content.add(new Object ()); 217 this.content.add("s1"); 218 this.content.add(new Double (1)); 219 this.content.add("s2"); 220 this.content.add(new Object ()); 221 this.content.add("s3"); 222 this.content.add(new Double (0)); 223 } 224 225 226 231 protected void tearDown() 232 throws Exception 233 { 234 this.content = null; 235 } 236 } 237 | Popular Tags |