1 16 package javax.faces.component; 17 18 import junit.framework.TestCase; 19 20 import java.util.ArrayList ; 21 import java.util.Arrays ; 22 import java.util.Collections ; 23 import java.util.List ; 24 25 36 public class UISelectManyTest 37 extends TestCase 38 { 39 41 public void testComparePrimitiveArrays() 42 { 43 UISelectMany selectMany = new UISelectMany(); 44 int[] intArray1; 45 int[] intArray2; 46 boolean[] boolArray1; 47 boolean[] boolArray2; 48 49 intArray1 = new int[] {1, 2, 3}; 51 intArray2 = new int[] {2, 3, 1}; 52 assertFalse(selectMany.compareValues(intArray1, intArray2)); 53 assertFalse(selectMany.compareValues(intArray2, intArray1)); 54 55 intArray1 = new int[] {1, 2, 3}; 56 intArray2 = new int[] {1, 2, 3}; 57 assertFalse(selectMany.compareValues(intArray1, intArray2)); 58 assertFalse(selectMany.compareValues(intArray2, intArray1)); 59 60 intArray1 = new int[] {}; 61 intArray2 = new int[] {}; 62 assertFalse(selectMany.compareValues(intArray1, intArray2)); 63 assertFalse(selectMany.compareValues(intArray2, intArray1)); 64 65 intArray1 = new int[] {1, 2, 2, 3, 3, 3, 4}; 66 intArray2 = new int[] {1, 4, 2, 3, 2, 3, 3}; 67 assertFalse(selectMany.compareValues(intArray1, intArray2)); 68 assertFalse(selectMany.compareValues(intArray2, intArray1)); 69 70 boolArray1 = new boolean[] {true, true, false, false, false}; 71 boolArray2 = new boolean[] {true, false, true, false, false}; 72 assertFalse(selectMany.compareValues(boolArray1, boolArray2)); 73 assertFalse(selectMany.compareValues(boolArray2, boolArray1)); 74 75 intArray1 = null; 76 intArray2 = null; 77 assertFalse(selectMany.compareValues(intArray1, intArray2)); 78 assertFalse(selectMany.compareValues(intArray2, intArray1)); 79 80 81 83 intArray1 = new int[] {1, 2, 3}; 84 intArray2 = new int[] {1, 2, 3, 4}; 85 assertTrue(selectMany.compareValues(intArray1, intArray2)); 86 assertTrue(selectMany.compareValues(intArray2, intArray1)); 87 88 intArray1 = new int[] {}; 89 intArray2 = new int[] {1, 2, 3, 4}; 90 assertTrue(selectMany.compareValues(intArray1, intArray2)); 91 assertTrue(selectMany.compareValues(intArray2, intArray1)); 92 93 intArray1 = new int[] {1, 2, 3, 4}; 94 intArray2 = new int[] {1, 2, 5, 4}; 95 assertTrue(selectMany.compareValues(intArray1, intArray2)); 96 assertTrue(selectMany.compareValues(intArray2, intArray1)); 97 98 intArray1 = new int[] {1, 2, 2, 3, 3, 3, 4}; 99 intArray2 = new int[] {1, 2, 2, 2, 3, 3, 4}; 100 assertTrue(selectMany.compareValues(intArray1, intArray2)); 101 assertTrue(selectMany.compareValues(intArray2, intArray1)); 102 103 intArray1 = new int[] {1, 2, 2, 3, 3, 3, 4}; 104 intArray2 = new int[] {1, 4, 2, 3, 2, 3, 2}; 105 assertTrue(selectMany.compareValues(intArray1, intArray2)); 106 assertTrue(selectMany.compareValues(intArray2, intArray1)); 107 108 boolArray1 = new boolean[] {true, true, false, false, false}; 109 boolArray2 = new boolean[] {true, false, true, false, true}; 110 assertTrue(selectMany.compareValues(boolArray1, boolArray2)); 111 assertTrue(selectMany.compareValues(boolArray2, boolArray1)); 112 113 intArray1 = new int[] {1, 2, 3}; 114 intArray2 = null; 115 assertTrue(selectMany.compareValues(intArray1, intArray2)); 116 assertTrue(selectMany.compareValues(intArray2, intArray1)); 117 118 } 119 120 121 public void testCompareObjectArrays() 122 { 123 UISelectMany selectMany = new UISelectMany(); 124 Object [] array1; 125 Object [] array2; 126 int[] intArray; 127 128 array1 = new Object [] {"1", "2", "3"}; 130 array2 = new Object [] {"2", "3", "1"}; 131 assertFalse(selectMany.compareValues(array1, array2)); 132 assertFalse(selectMany.compareValues(array2, array1)); 133 134 array1 = new Object [] {"1", "2", "3"}; 135 array2 = new Object [] {"1", "2", "3"}; 136 assertFalse(selectMany.compareValues(array1, array2)); 137 assertFalse(selectMany.compareValues(array2, array1)); 138 139 array1 = new Object [] {}; 140 array2 = new Object [] {}; 141 assertFalse(selectMany.compareValues(array1, array2)); 142 assertFalse(selectMany.compareValues(array2, array1)); 143 144 array1 = new Object [] {"1", "2", "2", "3", "3", "3", "4"}; 145 array2 = new Object [] {"1", "4", "2", "3", "2", "3", "3"}; 146 assertFalse(selectMany.compareValues(array1, array2)); 147 assertFalse(selectMany.compareValues(array2, array1)); 148 149 array1 = new Object [] {"1", new Long (2), "2", "3", "3", "3", "4"}; 150 array2 = new Object [] {"1", "4", "2", "3", new Long (2), "3", "3"}; 151 assertFalse(selectMany.compareValues(array1, array2)); 152 assertFalse(selectMany.compareValues(array2, array1)); 153 154 array1 = null; 155 array2 = null; 156 assertFalse(selectMany.compareValues(array1, array2)); 157 assertFalse(selectMany.compareValues(array2, array1)); 158 159 160 162 array1 = new Object [] {"1", "2", "3"}; 163 array2 = new Object [] {"1", "2", "3", "4"}; 164 assertTrue(selectMany.compareValues(array1, array2)); 165 assertTrue(selectMany.compareValues(array2, array1)); 166 167 array1 = new Object [] {}; 168 array2 = new Object [] {"1", "2", "3", "4"}; 169 assertTrue(selectMany.compareValues(array1, array2)); 170 assertTrue(selectMany.compareValues(array2, array1)); 171 172 array1 = new Object [] {"1", "2", "3", "4"}; 173 array2 = new Object [] {"1", "2", "5", "4"}; 174 assertTrue(selectMany.compareValues(array1, array2)); 175 assertTrue(selectMany.compareValues(array2, array1)); 176 177 array1 = new Object [] {"1", "2", "2", "3", "3", "3", "4"}; 178 array2 = new Object [] {"1", "2", "2", "2", "3", "3", "4"}; 179 assertTrue(selectMany.compareValues(array1, array2)); 180 assertTrue(selectMany.compareValues(array2, array1)); 181 182 array1 = new Object [] {"1", "2", "2", "3", "3", "3", "4"}; 183 array2 = new Object [] {"1", "4", "2", "3", "2", "3", "2"}; 184 assertTrue(selectMany.compareValues(array1, array2)); 185 assertTrue(selectMany.compareValues(array2, array1)); 186 187 array1 = new Object [] {"1", new Long (2), "2", "3", "3", "3", "4"}; 188 array2 = new Object [] {"1", "4", "2", "3", new Integer (2), "3", "3"}; 189 assertTrue(selectMany.compareValues(array1, array2)); 190 assertTrue(selectMany.compareValues(array2, array1)); 191 192 array1 = new Object [] {"1", "2", "3", "4"}; 193 intArray = new int[] {1, 2, 3, 4}; 194 assertTrue(selectMany.compareValues(array1, intArray)); 195 assertTrue(selectMany.compareValues(intArray, array1)); 196 197 array1 = new Object [] {"1", "2"}; 198 array2 = null; 199 assertTrue(selectMany.compareValues(array1, array2)); 200 assertTrue(selectMany.compareValues(array2, array1)); 201 202 array1 = new Object [] {}; 203 array2 = null; 204 assertTrue(selectMany.compareValues(array1, array2)); 205 assertTrue(selectMany.compareValues(array2, array1)); 206 207 } 208 209 210 public void testCompareLists() 211 { 212 UISelectMany selectMany = new UISelectMany(); 213 List list1; 214 List list2; 215 int[] intArray; 216 Object [] objArray; 217 218 list1 = Arrays.asList(new Object [] {"1", "2", "3"}); 220 list2 = Arrays.asList(new Object [] {"2", "3", "1"}); 221 assertFalse(selectMany.compareValues(list1, list2)); 222 assertFalse(selectMany.compareValues(list2, list1)); 223 224 list1 = Arrays.asList(new Object [] {"1", "2", "3"}); 225 list2 = Arrays.asList(new Object [] {"1", "2", "3"}); 226 assertFalse(selectMany.compareValues(list1, list2)); 227 assertFalse(selectMany.compareValues(list2, list1)); 228 229 list1 = new ArrayList (); 230 list2 = Collections.EMPTY_LIST; 231 assertFalse(selectMany.compareValues(list1, list2)); 232 assertFalse(selectMany.compareValues(list2, list1)); 233 234 list1 = Arrays.asList(new Object [] {"1", "2", "2", "3", "3", "3", "4"}); 235 list2 = Arrays.asList(new Object [] {"1", "4", "2", "3", "2", "3", "3"}); 236 assertFalse(selectMany.compareValues(list1, list2)); 237 assertFalse(selectMany.compareValues(list2, list1)); 238 239 list1 = Arrays.asList(new Object [] {"1", new Long (2), "2", "3", "3", "3", "4"}); 240 list2 = Arrays.asList(new Object [] {"1", "4", "2", "3", new Long (2), "3", "3"}); 241 assertFalse(selectMany.compareValues(list1, list2)); 242 assertFalse(selectMany.compareValues(list2, list1)); 243 244 list1 = null; 245 list2 = null; 246 assertFalse(selectMany.compareValues(list1, list2)); 247 assertFalse(selectMany.compareValues(list2, list1)); 248 249 250 252 list1 = Arrays.asList(new Object [] {"1", "2", "3"}); 253 list2 = Arrays.asList(new Object [] {"1", "2", "3", "4"}); 254 assertTrue(selectMany.compareValues(list1, list2)); 255 assertTrue(selectMany.compareValues(list2, list1)); 256 257 list1 = Arrays.asList(new Object [] {}); 258 list2 = Arrays.asList(new Object [] {"1", "2", "3", "4"}); 259 assertTrue(selectMany.compareValues(list1, list2)); 260 assertTrue(selectMany.compareValues(list2, list1)); 261 262 list1 = Arrays.asList(new Object [] {"1", "2", "3", "4"}); 263 list2 = Arrays.asList(new Object [] {"1", "2", "5", "4"}); 264 assertTrue(selectMany.compareValues(list1, list2)); 265 assertTrue(selectMany.compareValues(list2, list1)); 266 267 list1 = Arrays.asList(new Object [] {"1", "2", "2", "3", "3", "3", "4"}); 268 list2 = Arrays.asList(new Object [] {"1", "2", "2", "2", "3", "3", "4"}); 269 assertTrue(selectMany.compareValues(list1, list2)); 270 assertTrue(selectMany.compareValues(list2, list1)); 271 272 list1 = Arrays.asList(new Object [] {"1", "2", "2", "3", "3", "3", "4"}); 273 list2 = Arrays.asList(new Object [] {"1", "4", "2", "3", "2", "3", "2"}); 274 assertTrue(selectMany.compareValues(list1, list2)); 275 assertTrue(selectMany.compareValues(list2, list1)); 276 277 list1 = Arrays.asList(new Object [] {"1", new Long (2), "2", "3", "3", "3", "4"}); 278 list2 = Arrays.asList(new Object [] {"1", "4", "2", "3", new Integer (2), "3", "3"}); 279 assertTrue(selectMany.compareValues(list1, list2)); 280 assertTrue(selectMany.compareValues(list2, list1)); 281 282 list1 = Arrays.asList(new Object [] {"1", "2", "3", "4"}); 283 intArray = new int[] {1, 2, 3, 4}; 284 assertTrue(selectMany.compareValues(list1, intArray)); 285 assertTrue(selectMany.compareValues(intArray, list1)); 286 287 list1 = Arrays.asList(new Object [] {"1", "2"}); 288 objArray = new Object [] {"1", "2"}; 289 assertTrue(selectMany.compareValues(list1, objArray)); 290 assertTrue(selectMany.compareValues(objArray, list1)); 291 292 list1 = Arrays.asList(new Object [] {"1", "2"}); 293 list2 = null; 294 assertTrue(selectMany.compareValues(list1, list2)); 295 assertTrue(selectMany.compareValues(list2, list1)); 296 297 list1 = Arrays.asList(new Object [] {}); 298 list2 = null; 299 assertTrue(selectMany.compareValues(list1, list2)); 300 assertTrue(selectMany.compareValues(list2, list1)); 301 302 } 303 304 305 } 306 | Popular Tags |