KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > BooleanUtilsTest


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang;
17
18 import java.lang.reflect.Constructor JavaDoc;
19 import java.lang.reflect.Modifier JavaDoc;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25
26 /**
27  * Unit tests {@link org.apache.commons.lang.BooleanUtils}.
28  *
29  * @author Stephen Colebourne
30  * @author Matthew Hawthorne
31  * @version $Id: BooleanUtilsTest.java 161244 2005-04-14 06:16:36Z ggregory $
32  */

33 public class BooleanUtilsTest extends TestCase {
34
35     public BooleanUtilsTest(String JavaDoc name) {
36         super(name);
37     }
38
39     public static void main(String JavaDoc[] args) {
40         TestRunner.run(suite());
41     }
42
43     public static Test suite() {
44         TestSuite suite = new TestSuite(BooleanUtilsTest.class);
45         suite.setName("BooleanUtils Tests");
46         return suite;
47     }
48
49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51     }
52
53     protected void tearDown() throws Exception JavaDoc {
54         super.tearDown();
55     }
56
57     //-----------------------------------------------------------------------
58
public void testConstructor() {
59         assertNotNull(new BooleanUtils());
60         Constructor JavaDoc[] cons = BooleanUtils.class.getDeclaredConstructors();
61         assertEquals(1, cons.length);
62         assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
63         assertEquals(true, Modifier.isPublic(BooleanUtils.class.getModifiers()));
64         assertEquals(false, Modifier.isFinal(BooleanUtils.class.getModifiers()));
65     }
66     
67     //-----------------------------------------------------------------------
68
public void test_negate_Boolean() {
69         assertSame(null, BooleanUtils.negate(null));
70         assertSame(Boolean.TRUE, BooleanUtils.negate(Boolean.FALSE));
71         assertSame(Boolean.FALSE, BooleanUtils.negate(Boolean.TRUE));
72     }
73
74     //-----------------------------------------------------------------------
75
public void test_isTrue_Boolean() {
76         assertEquals(true, BooleanUtils.isTrue(Boolean.TRUE));
77         assertEquals(false, BooleanUtils.isTrue(Boolean.FALSE));
78         assertEquals(false, BooleanUtils.isTrue((Boolean JavaDoc) null));
79     }
80
81     public void test_isFalse_Boolean() {
82         assertEquals(false, BooleanUtils.isFalse(Boolean.TRUE));
83         assertEquals(true, BooleanUtils.isFalse(Boolean.FALSE));
84         assertEquals(false, BooleanUtils.isFalse((Boolean JavaDoc) null));
85     }
86
87     //-----------------------------------------------------------------------
88
public void test_toBooleanObject_boolean() {
89         assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(true));
90         assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject(false));
91     }
92
93     public void test_toBoolean_Boolean() {
94         assertEquals(true, BooleanUtils.toBoolean(Boolean.TRUE));
95         assertEquals(false, BooleanUtils.toBoolean(Boolean.FALSE));
96         assertEquals(false, BooleanUtils.toBoolean((Boolean JavaDoc) null));
97     }
98
99     public void test_toBooleanDefaultIfNull_Boolean_boolean() {
100         assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, true));
101         assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false));
102         assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true));
103         assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, false));
104         assertEquals(true, BooleanUtils.toBooleanDefaultIfNull((Boolean JavaDoc) null, true));
105         assertEquals(false, BooleanUtils.toBooleanDefaultIfNull((Boolean JavaDoc) null, false));
106     }
107
108     //-----------------------------------------------------------------------
109
//-----------------------------------------------------------------------
110
public void test_toBoolean_int() {
111         assertEquals(true, BooleanUtils.toBoolean(1));
112         assertEquals(true, BooleanUtils.toBoolean(-1));
113         assertEquals(false, BooleanUtils.toBoolean(0));
114     }
115     
116     public void test_toBooleanObject_int() {
117         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(1));
118         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(-1));
119         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(0));
120     }
121     
122     public void test_toBooleanObject_Integer() {
123         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(new Integer JavaDoc(1)));
124         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(new Integer JavaDoc(-1)));
125         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(new Integer JavaDoc(0)));
126         assertEquals(null, BooleanUtils.toBooleanObject((Integer JavaDoc) null));
127     }
128     
129     //-----------------------------------------------------------------------
130
public void test_toBoolean_int_int_int() {
131         assertEquals(true, BooleanUtils.toBoolean(6, 6, 7));
132         assertEquals(false, BooleanUtils.toBoolean(7, 6, 7));
133         try {
134             BooleanUtils.toBoolean(8, 6, 7);
135             fail();
136         } catch (IllegalArgumentException JavaDoc ex) {}
137     }
138     
139     public void test_toBoolean_Integer_Integer_Integer() {
140         Integer JavaDoc six = new Integer JavaDoc(6);
141         Integer JavaDoc seven = new Integer JavaDoc(7);
142
143         assertEquals(true, BooleanUtils.toBoolean((Integer JavaDoc) null, null, seven));
144         assertEquals(false, BooleanUtils.toBoolean((Integer JavaDoc) null, six, null));
145         try {
146             BooleanUtils.toBoolean(null, six, seven);
147             fail();
148         } catch (IllegalArgumentException JavaDoc ex) {}
149         
150         assertEquals(true, BooleanUtils.toBoolean(new Integer JavaDoc(6), six, seven));
151         assertEquals(false, BooleanUtils.toBoolean(new Integer JavaDoc(7), six, seven));
152         try {
153             BooleanUtils.toBoolean(new Integer JavaDoc(8), six, seven);
154             fail();
155         } catch (IllegalArgumentException JavaDoc ex) {}
156     }
157     
158     //-----------------------------------------------------------------------
159
public void test_toBooleanObject_int_int_int() {
160         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(6, 6, 7, 8));
161         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(7, 6, 7, 8));
162         assertEquals(null, BooleanUtils.toBooleanObject(8, 6, 7, 8));
163         try {
164             BooleanUtils.toBooleanObject(9, 6, 7, 8);
165             fail();
166         } catch (IllegalArgumentException JavaDoc ex) {}
167     }
168     
169     public void test_toBooleanObject_Integer_Integer_Integer_Integer() {
170         Integer JavaDoc six = new Integer JavaDoc(6);
171         Integer JavaDoc seven = new Integer JavaDoc(7);
172         Integer JavaDoc eight = new Integer JavaDoc(8);
173
174         assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((Integer JavaDoc) null, null, seven, eight));
175         assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((Integer JavaDoc) null, six, null, eight));
176         assertSame(null, BooleanUtils.toBooleanObject((Integer JavaDoc) null, six, seven, null));
177         try {
178             BooleanUtils.toBooleanObject(null, six, seven, eight);
179             fail();
180         } catch (IllegalArgumentException JavaDoc ex) {}
181         
182         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(new Integer JavaDoc(6), six, seven, eight));
183         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(new Integer JavaDoc(7), six, seven, eight));
184         assertEquals(null, BooleanUtils.toBooleanObject(new Integer JavaDoc(8), six, seven, eight));
185         try {
186             BooleanUtils.toBooleanObject(new Integer JavaDoc(9), six, seven, eight);
187             fail();
188         } catch (IllegalArgumentException JavaDoc ex) {}
189     }
190     
191     //-----------------------------------------------------------------------
192
public void test_toInteger_boolean() {
193         assertEquals(1, BooleanUtils.toInteger(true));
194         assertEquals(0, BooleanUtils.toInteger(false));
195     }
196     
197     public void test_toIntegerObject_boolean() {
198         assertEquals(new Integer JavaDoc(1), BooleanUtils.toIntegerObject(true));
199         assertEquals(new Integer JavaDoc(0), BooleanUtils.toIntegerObject(false));
200     }
201     
202     public void test_toIntegerObject_Boolean() {
203         assertEquals(new Integer JavaDoc(1), BooleanUtils.toIntegerObject(Boolean.TRUE));
204         assertEquals(new Integer JavaDoc(0), BooleanUtils.toIntegerObject(Boolean.FALSE));
205         assertEquals(null, BooleanUtils.toIntegerObject((Boolean JavaDoc) null));
206     }
207     
208     //-----------------------------------------------------------------------
209
public void test_toInteger_boolean_int_int() {
210         assertEquals(6, BooleanUtils.toInteger(true, 6, 7));
211         assertEquals(7, BooleanUtils.toInteger(false, 6, 7));
212     }
213     
214     public void test_toInteger_Boolean_int_int_int() {
215         assertEquals(6, BooleanUtils.toInteger(Boolean.TRUE, 6, 7, 8));
216         assertEquals(7, BooleanUtils.toInteger(Boolean.FALSE, 6, 7, 8));
217         assertEquals(8, BooleanUtils.toInteger(null, 6, 7, 8));
218     }
219     
220     public void test_toIntegerObject_boolean_Integer_Integer() {
221         Integer JavaDoc six = new Integer JavaDoc(6);
222         Integer JavaDoc seven = new Integer JavaDoc(7);
223         assertEquals(six, BooleanUtils.toIntegerObject(true, six, seven));
224         assertEquals(seven, BooleanUtils.toIntegerObject(false, six, seven));
225     }
226     
227     public void test_toIntegerObject_Boolean_Integer_Integer_Integer() {
228         Integer JavaDoc six = new Integer JavaDoc(6);
229         Integer JavaDoc seven = new Integer JavaDoc(7);
230         Integer JavaDoc eight = new Integer JavaDoc(8);
231         assertEquals(six, BooleanUtils.toIntegerObject(Boolean.TRUE, six, seven, eight));
232         assertEquals(seven, BooleanUtils.toIntegerObject(Boolean.FALSE, six, seven, eight));
233         assertEquals(eight, BooleanUtils.toIntegerObject((Boolean JavaDoc) null, six, seven, eight));
234         assertEquals(null, BooleanUtils.toIntegerObject((Boolean JavaDoc) null, six, seven, null));
235     }
236     
237     //-----------------------------------------------------------------------
238
//-----------------------------------------------------------------------
239
public void test_toBooleanObject_String() {
240         assertEquals(null, BooleanUtils.toBooleanObject((String JavaDoc) null));
241         assertEquals(null, BooleanUtils.toBooleanObject(""));
242         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("false"));
243         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("no"));
244         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("off"));
245         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("FALSE"));
246         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("NO"));
247         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("OFF"));
248         assertEquals(null, BooleanUtils.toBooleanObject("oof"));
249         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("true"));
250         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("yes"));
251         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("on"));
252         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TRUE"));
253         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("ON"));
254         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("YES"));
255         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TruE"));
256     }
257     
258     public void test_toBooleanObject_String_String_String_String() {
259         assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((String JavaDoc) null, null, "N", "U"));
260         assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((String JavaDoc) null, "Y", null, "U"));
261         assertSame(null, BooleanUtils.toBooleanObject((String JavaDoc) null, "Y", "N", null));
262         try {
263             BooleanUtils.toBooleanObject((String JavaDoc) null, "Y", "N", "U");
264             fail();
265         } catch (IllegalArgumentException JavaDoc ex) {}
266
267         assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("Y", "Y", "N", "U"));
268         assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("N", "Y", "N", "U"));
269         assertEquals(null, BooleanUtils.toBooleanObject("U", "Y", "N", "U"));
270         try {
271             BooleanUtils.toBooleanObject(null, "Y", "N", "U");
272             fail();
273         } catch (IllegalArgumentException JavaDoc ex) {}
274         try {
275             BooleanUtils.toBooleanObject("X", "Y", "N", "U");
276             fail();
277         } catch (IllegalArgumentException JavaDoc ex) {}
278     }
279
280     //-----------------------------------------------------------------------
281
public void test_toBoolean_String() {
282         assertEquals(false, BooleanUtils.toBoolean((String JavaDoc) null));
283         assertEquals(false, BooleanUtils.toBoolean(""));
284         assertEquals(false, BooleanUtils.toBoolean("off"));
285         assertEquals(false, BooleanUtils.toBoolean("oof"));
286         assertEquals(false, BooleanUtils.toBoolean("yep"));
287         assertEquals(false, BooleanUtils.toBoolean("trux"));
288         assertEquals(false, BooleanUtils.toBoolean("false"));
289         assertEquals(false, BooleanUtils.toBoolean("a"));
290         assertEquals(true, BooleanUtils.toBoolean("true")); // interned handled differently
291
assertEquals(true, BooleanUtils.toBoolean(new StringBuffer JavaDoc("tr").append("ue").toString()));
292         assertEquals(true, BooleanUtils.toBoolean("truE"));
293         assertEquals(true, BooleanUtils.toBoolean("trUe"));
294         assertEquals(true, BooleanUtils.toBoolean("trUE"));
295         assertEquals(true, BooleanUtils.toBoolean("tRue"));
296         assertEquals(true, BooleanUtils.toBoolean("tRuE"));
297         assertEquals(true, BooleanUtils.toBoolean("tRUe"));
298         assertEquals(true, BooleanUtils.toBoolean("tRUE"));
299         assertEquals(true, BooleanUtils.toBoolean("TRUE"));
300         assertEquals(true, BooleanUtils.toBoolean("TRUe"));
301         assertEquals(true, BooleanUtils.toBoolean("TRuE"));
302         assertEquals(true, BooleanUtils.toBoolean("TRue"));
303         assertEquals(true, BooleanUtils.toBoolean("TrUE"));
304         assertEquals(true, BooleanUtils.toBoolean("TrUe"));
305         assertEquals(true, BooleanUtils.toBoolean("TruE"));
306         assertEquals(true, BooleanUtils.toBoolean("True"));
307         assertEquals(true, BooleanUtils.toBoolean("on"));
308         assertEquals(true, BooleanUtils.toBoolean("oN"));
309         assertEquals(true, BooleanUtils.toBoolean("On"));
310         assertEquals(true, BooleanUtils.toBoolean("ON"));
311         assertEquals(true, BooleanUtils.toBoolean("yes"));
312         assertEquals(true, BooleanUtils.toBoolean("yeS"));
313         assertEquals(true, BooleanUtils.toBoolean("yEs"));
314         assertEquals(true, BooleanUtils.toBoolean("yES"));
315         assertEquals(true, BooleanUtils.toBoolean("Yes"));
316         assertEquals(true, BooleanUtils.toBoolean("YeS"));
317         assertEquals(true, BooleanUtils.toBoolean("YEs"));
318         assertEquals(true, BooleanUtils.toBoolean("YES"));
319     }
320
321     public void test_toBoolean_String_String_String() {
322         assertEquals(true, BooleanUtils.toBoolean((String JavaDoc) null, null, "N"));
323         assertEquals(false, BooleanUtils.toBoolean((String JavaDoc) null, "Y", null));
324         try {
325             BooleanUtils.toBooleanObject((String JavaDoc) null, "Y", "N", "U");
326             fail();
327         } catch (IllegalArgumentException JavaDoc ex) {}
328         
329         assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "N"));
330         assertEquals(false, BooleanUtils.toBoolean("N", "Y", "N"));
331         try {
332             BooleanUtils.toBoolean(null, "Y", "N");
333             fail();
334         } catch (IllegalArgumentException JavaDoc ex) {}
335         try {
336             BooleanUtils.toBoolean("X", "Y", "N");
337             fail();
338         } catch (IllegalArgumentException JavaDoc ex) {}
339     }
340
341     //-----------------------------------------------------------------------
342
public void test_toStringTrueFalse_Boolean() {
343         assertEquals(null, BooleanUtils.toStringTrueFalse((Boolean JavaDoc) null));
344         assertEquals("true", BooleanUtils.toStringTrueFalse(Boolean.TRUE));
345         assertEquals("false", BooleanUtils.toStringTrueFalse(Boolean.FALSE));
346     }
347     
348     public void test_toStringOnOff_Boolean() {
349         assertEquals(null, BooleanUtils.toStringOnOff((Boolean JavaDoc) null));
350         assertEquals("on", BooleanUtils.toStringOnOff(Boolean.TRUE));
351         assertEquals("off", BooleanUtils.toStringOnOff(Boolean.FALSE));
352     }
353     
354     public void test_toStringYesNo_Boolean() {
355         assertEquals(null, BooleanUtils.toStringYesNo((Boolean JavaDoc) null));
356         assertEquals("yes", BooleanUtils.toStringYesNo(Boolean.TRUE));
357         assertEquals("no", BooleanUtils.toStringYesNo(Boolean.FALSE));
358     }
359     
360     public void test_toString_Boolean_String_String_String() {
361         assertEquals("U", BooleanUtils.toString((Boolean JavaDoc) null, "Y", "N", "U"));
362         assertEquals("Y", BooleanUtils.toString(Boolean.TRUE, "Y", "N", "U"));
363         assertEquals("N", BooleanUtils.toString(Boolean.FALSE, "Y", "N", "U"));
364     }
365     
366     //-----------------------------------------------------------------------
367
public void test_toStringTrueFalse_boolean() {
368         assertEquals("true", BooleanUtils.toStringTrueFalse(true));
369         assertEquals("false", BooleanUtils.toStringTrueFalse(false));
370     }
371     
372     public void test_toStringOnOff_boolean() {
373         assertEquals("on", BooleanUtils.toStringOnOff(true));
374         assertEquals("off", BooleanUtils.toStringOnOff(false));
375     }
376     
377     public void test_toStringYesNo_boolean() {
378         assertEquals("yes", BooleanUtils.toStringYesNo(true));
379         assertEquals("no", BooleanUtils.toStringYesNo(false));
380     }
381     
382     public void test_toString_boolean_String_String_String() {
383         assertEquals("Y", BooleanUtils.toString(true, "Y", "N"));
384         assertEquals("N", BooleanUtils.toString(false, "Y", "N"));
385     }
386     
387     // testXor
388
// -----------------------------------------------------------------------
389
public void testXor_primitive_nullInput() {
390         final boolean[] b = null;
391         try {
392             BooleanUtils.xor(b);
393             fail("Exception was not thrown for null input.");
394         } catch (IllegalArgumentException JavaDoc ex) {}
395     }
396
397     public void testXor_primitive_emptyInput() {
398         try {
399             BooleanUtils.xor(new boolean[] {});
400             fail("Exception was not thrown for empty input.");
401         } catch (IllegalArgumentException JavaDoc ex) {}
402     }
403
404     public void testXor_primitive_validInput_2items() {
405         assertTrue(
406             "True result for (true, true)",
407             ! BooleanUtils.xor(new boolean[] { true, true }));
408
409         assertTrue(
410             "True result for (false, false)",
411             ! BooleanUtils.xor(new boolean[] { false, false }));
412
413         assertTrue(
414             "False result for (true, false)",
415             BooleanUtils.xor(new boolean[] { true, false }));
416
417         assertTrue(
418             "False result for (false, true)",
419             BooleanUtils.xor(new boolean[] { false, true }));
420     }
421
422     public void testXor_primitive_validInput_3items() {
423         assertTrue(
424             "False result for (false, false, true)",
425             BooleanUtils.xor(new boolean[] { false, false, true }));
426
427         assertTrue(
428             "False result for (false, true, false)",
429             BooleanUtils.xor(new boolean[] { false, true, false }));
430
431         assertTrue(
432             "False result for (true, false, false)",
433             BooleanUtils.xor(new boolean[] { true, false, false }));
434
435         assertTrue(
436             "True result for (true, true, true)",
437             ! BooleanUtils.xor(new boolean[] { true, true, true }));
438
439         assertTrue(
440             "True result for (false, false)",
441             ! BooleanUtils.xor(new boolean[] { false, false, false }));
442
443         assertTrue(
444             "True result for (true, true, false)",
445             ! BooleanUtils.xor(new boolean[] { true, true, false }));
446
447         assertTrue(
448             "True result for (true, false, true)",
449             ! BooleanUtils.xor(new boolean[] { true, false, true }));
450
451         assertTrue(
452             "False result for (false, true, true)",
453             ! BooleanUtils.xor(new boolean[] { false, true, true }));
454     }
455
456     public void testXor_object_nullInput() {
457         final Boolean JavaDoc[] b = null;
458         try {
459             BooleanUtils.xor(b);
460             fail("Exception was not thrown for null input.");
461         } catch (IllegalArgumentException JavaDoc ex) {}
462     }
463
464     public void testXor_object_emptyInput() {
465         try {
466             BooleanUtils.xor(new Boolean JavaDoc[] {});
467             fail("Exception was not thrown for empty input.");
468         } catch (IllegalArgumentException JavaDoc ex) {}
469     }
470     
471     public void testXor_object_nullElementInput() {
472         try {
473             BooleanUtils.xor(new Boolean JavaDoc[] {null});
474             fail("Exception was not thrown for null element input.");
475         } catch (IllegalArgumentException JavaDoc ex) {}
476     }
477
478     public void testXor_object_validInput_2items() {
479         assertTrue(
480             "True result for (true, true)",
481             ! BooleanUtils
482                 .xor(new Boolean JavaDoc[] { Boolean.TRUE, Boolean.TRUE })
483                 .booleanValue());
484
485         assertTrue(
486             "True result for (false, false)",
487             ! BooleanUtils
488                 .xor(new Boolean JavaDoc[] { Boolean.FALSE, Boolean.FALSE })
489                 .booleanValue());
490
491         assertTrue(
492             "False result for (true, false)",
493             BooleanUtils
494                 .xor(new Boolean JavaDoc[] { Boolean.TRUE, Boolean.FALSE })
495                 .booleanValue());
496
497         assertTrue(
498             "False result for (false, true)",
499             BooleanUtils
500                 .xor(new Boolean JavaDoc[] { Boolean.FALSE, Boolean.TRUE })
501                 .booleanValue());
502     }
503
504     public void testXor_object_validInput_3items() {
505         assertTrue(
506             "False result for (false, false, true)",
507             BooleanUtils
508                 .xor(
509                     new Boolean JavaDoc[] {
510                         Boolean.FALSE,
511                         Boolean.FALSE,
512                         Boolean.TRUE })
513                 .booleanValue());
514
515         assertTrue(
516             "False result for (false, true, false)",
517             BooleanUtils
518                 .xor(
519                     new Boolean JavaDoc[] {
520                         Boolean.FALSE,
521                         Boolean.TRUE,
522                         Boolean.FALSE })
523                 .booleanValue());
524
525         assertTrue(
526             "False result for (true, false, false)",
527             BooleanUtils
528                 .xor(
529                     new Boolean JavaDoc[] {
530                         Boolean.TRUE,
531                         Boolean.FALSE,
532                         Boolean.FALSE })
533                 .booleanValue());
534
535         assertTrue(
536             "True result for (true, true, true)",
537             ! BooleanUtils
538                 .xor(new Boolean JavaDoc[] { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE })
539                 .booleanValue());
540
541         assertTrue(
542             "True result for (false, false)",
543             ! BooleanUtils.xor(
544                     new Boolean JavaDoc[] {
545                         Boolean.FALSE,
546                         Boolean.FALSE,
547                         Boolean.FALSE })
548                 .booleanValue());
549
550         assertTrue(
551             "True result for (true, true, false)",
552             ! BooleanUtils.xor(
553                     new Boolean JavaDoc[] {
554                         Boolean.TRUE,
555                         Boolean.TRUE,
556                         Boolean.FALSE })
557                 .booleanValue());
558
559         assertTrue(
560             "True result for (true, false, true)",
561             ! BooleanUtils.xor(
562                     new Boolean JavaDoc[] {
563                         Boolean.TRUE,
564                         Boolean.FALSE,
565                         Boolean.TRUE })
566                 .booleanValue());
567
568         assertTrue(
569             "False result for (false, true, true)",
570             ! BooleanUtils.xor(
571                     new Boolean JavaDoc[] {
572                         Boolean.FALSE,
573                         Boolean.TRUE,
574                         Boolean.TRUE })
575                 .booleanValue());
576                 
577     }
578
579 }
580
Popular Tags